-
Ifstream problems
Hello!
I have the following code:
...
std::ifstream strm( fname );
...
strm >> Var1 >> Var2;
...
strm.getline( s, STRING_LENGTH );
The problem is that when i try to read the line 2 of the file with getline then i get nothing, but when i read a char after Vars2 for ex.
strm >> Var1 >> Var2 >> a;
...then i get the first char from the second line. Is there a problem when i mix >> and getline???
After i read the char the function getline reads the string correctly but without the beginning char.
Anyone an idea...
Thanks
-
I guess it must be that you have to set the position in the file first before you start to getline() just like what we do with FILE, we have to fsetpos() before fread()
The >> just set the position and then getline() works.
-
Solved the problem. I had to take the whitespace from the stream.