reading files

This is a discussion on reading files within the C++ Programming forums, part of the General Programming Boards category; i know how to read entire lines, but how do i read multiple lines? i currently use Code: read_file.getline(buffer,100); how ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    reading files

    i know how to read entire lines, but how do i read multiple lines?
    i currently use
    Code:
    read_file.getline(buffer,100);
    how would i read all lines in the file?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    put that code in a loop
    Code:
    while( read_file.getline(buffer,100) )
    {
       // do something such as copy the line someplace else
      // if you want to keep it.
    }

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Code:
    read_file.getline(buffer,100);
    read_file.getline(buffer,100);
    read_file.getline(buffer,100);
    read_file.getline(buffer,100);
    read_file.getline(buffer,100);
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    hey dragon, would that code keep reading till end of file?

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by rodrigorules
    hey dragon, would that code keep reading till end of file?
    yes. Search this board because it has been explained (to me too) several times.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading User Defined Files
    By Necrofear in forum C++ Programming
    Replies: 17
    Last Post: 06-30-2006, 01:55 AM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. reading files
    By hiya in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2005, 12:40 PM
  4. A little help reading from files...
    By Invincible in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2002, 10:43 AM
  5. Need Advice in reading files
    By jon in forum C Programming
    Replies: 4
    Last Post: 10-07-2001, 08:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21