I have an issue with the following code snippet.
I have a file referred to with the character array FileName
. The file could be basically anything, but in my case it is a file the contains some irrelevant text on the first line and then some lines that start with 1 (one) in one case and 0 (zero) in many other cases. So, my file is something like:
iewbFLUW 82494HJF VROIREBURV.TEXT
0 TEST whatever something
0 TEST words and more
1 TEST something something
0 TEST oefeowif
...
The intention of the my code snippet is that it picks the line selected with 1 (one).
// the stream object for my file:
string FileName = "myFile.text";
ifstream input(FileName);
// parsing the first line
char comment[1000];
input.getline(comment, 1000, '\n');
cout << comment << endl;
// parsing the other lines
bool select=false;
while (!input.eof())
{
input >> select;
cout << select << endl;
if(select){
// do something
}
}
However, although the FileName
starts the second line with a 0 (zero), the variable select
turns out to have value 1 right after the line input >> select;
How can this be?