Thread: Reading a user specificed line from a file

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    5

    Reading a user specificed line from a file

    I am trying to write a function to read a specific line from a file and assign it to C++ String type.
    I have opened the file using fopen and I do not know the length of the individual line of the file. Is there a library function that reads the whole line (line number specified by the user) using a delimiter? (say '\0' terminated strings)

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Use the global getline function.

    The first parameter is the stream.

    The second parameter is the std::string object to store the line.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    And while you're at it, take a look at the C++ Forum since you're actually on the C board.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Reading random line from a text file
    By helloamuro in forum C Programming
    Replies: 24
    Last Post: 05-03-2008, 10:57 PM
  3. Reading file line by line
    By chrisjmoss in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:58 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. reading file from second line
    By axon in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2003, 05:18 PM