Thread: text files

  1. #1
    Wannabe Geek
    Join Date
    Aug 2004
    Posts
    19

    Question text files

    I have created an input stream to read from a text file. I am able to read the first line using Infile.get(array,characters,'\n');
    How do i read the second line? How do i get the program to read the next line form the text file.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Call infile.get in a loop perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Call infile.getline() in a loop that checks for the .eof() flag to be set.

    What is EOF? and Why using feof() in a loop is bad, and ways to fix it.

  4. #4
    Wannabe Geek
    Join Date
    Aug 2004
    Posts
    19
    getfile keeps reading the same line. I tried it in a loop and it still reads only the first line. Could u plz give me a small example.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    std::ifstream file("yatta.txt");
    std::string line;
    
    while(still_reading_lines)
    {
      std::getline(file, line);
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Reading text files?
    By Kate in forum C Programming
    Replies: 3
    Last Post: 06-30-2006, 01:22 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. reading certain parts of text files
    By Captain Penguin in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2002, 09:45 AM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM