[SOLVED]using fstream and char arrays, reading junk from file
I have done some searching but because of the broad searching terms I have come accross countless websites that don't really deal with what it is I wish to know.
here is my code:
Code:
char currString[25];
ifstream levelFile("./Media/levels/level1.txt",std::ios::in);
while(!levelFile.eof()){
levelFile >> currString;
//levelFile.getline(currString,25);
if (currString=="##"){
//Ommited
} else if (currString=="Room_01"){
//Ommited
}
}
levelFile.close();
What I am trying to do is basically read some parameters from a .txt file to instantiate some objects later on.
I have multiple objects I want to instantiate from this one file, and I was planning on using "##" as a break between the objects. When I am debugging I also see garbage often before my actual text, such as instead of "Room_01" I might see something like "€@Room_01....".
Another problem I am having is that I have some parameters such as "-5" and then I may have paramater that is "matBoxMaterial", so if I load matBoxmaterial into currString first, when it comes to -5 I get
"-5xMatMaterial..."
and then all the other junk from the rest of the array. I guess my general question is, how can I read in just what is on that line? Or perhaps how can I clear the char array of garbage. I have contemplated using a terminator (like -5/0) but it just seems like I am missing something really obvious!
Any advice is always muchly appreciated.
nixius~
Last edited by nixius; February 23rd, 2008 at 02:03 PM.
Bookmarks