Thread: get a line from a file

  1. #1
    Registered User
    Join Date
    Dec 2004

    get a line from a file

    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You should be able to use the getline used with C++ strings.
    std::string str;
    std::getline(in, str); //in is some std::istream
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    Brazil, Porto Alegre
    Try this: getline()

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

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

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, 02: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
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM