CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2000
    Location
    Germany
    Posts
    369

    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

  2. #2
    Join Date
    Jun 2002
    Posts
    137
    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.

  3. #3
    Join Date
    May 2000
    Location
    Germany
    Posts
    369
    Solved the problem. I had to take the whitespace from the stream.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured