get a line from a file

This is a discussion on get a line from a file within the C++ Programming forums, part of the General Programming Boards category; Hi, I am stumped with getting a line from a file. I have read a lot of posts on this ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    get a line from a file

    Hi,
    I am stumped with getting a line from a file. I have read a lot of posts on this website but nothing seems to fit my problem. I would like to get lines from a file into strings. But the problem is that I do not know the length of each line of the file before hand and it would seem like the implementation of getline requires the maximum number of characters in a line. I don't know that. Any suggestions would be highly appreciated. Thanks
    Amish

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,754
    You should be able to use the getline used with C++ strings.
    Code:
    std::string str;
    std::getline(in, str); //in is some std::istream
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Try this: getline()

    edit: sorry laserlight, you were faster =P
    Last edited by Mortissus; 03-06-2006 at 09:55 AM.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    thanks just what i was looking for
    Amish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

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