Reading a user specificed line from a file

This is a discussion on Reading a user specificed line from a file within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a function to read a specific line from a file and assign it to C++ ...

  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
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    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, 11: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, 09:39 AM
  5. reading file from second line
    By axon in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2003, 05:18 PM

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