Click to See Complete Forum and Search --> : Ifstream problems


kakalake
July 9th, 2002, 06:19 PM
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

sandodo
July 9th, 2002, 09:51 PM
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.

kakalake
July 20th, 2002, 07:31 AM
Solved the problem. I had to take the whitespace from the stream.