CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: getline

  1. #1
    Join Date
    Sep 2008
    Posts
    26

    getline

    while ( getline ( infile, buffer ) ) {
    // Process the line
    }

    I'm reading a file from the stream to display in the console, but it only displays the first line how do I display the other lines?

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: getline

    You should be able to check for eof.
    Code:
    while (!infile.eof())
    {
    //read line from infile and process.
    }
    Last edited by ahoodin; November 17th, 2008 at 10:42 PM.
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Mar 2001
    Posts
    2,529

    Re: getline

    changed my post. Have a look.
    ahoodin
    To keep the plot moving, that's why.

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: getline

    1) the original code is correct. Supply a short program and a sample
    input file showing the error

    2) It is almost always an error in logic to put the eof() check as shown
    in the second post (as you need to check for eof() inside the loop
    also when reading in that way.

    Remember eof() is only true after ATTEMPTING to read past EOF.

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