Teen Programmers Unite  
 

 

Return to forum top

File reading in c++

Posted by gbyte222 [send private reply] at May 07, 2003, 10:25:28 PM

i know how to read a file, but how do i read only a certain line of a file?

Posted by buzgub [send private reply] at May 08, 2003, 01:26:58 AM

You know that you've found the end of the line when you encounter a '\n' character. If you count those, you'll know which line you're up to and can take some action on it.

Posted by whizkide [send private reply] at May 08, 2003, 09:08:25 AM

u have to know what he means by a line. if u use the standard programming definition then buzgub is okay. but if u wanna read a line like notepad wraps it to be, then u have to know the last character.
ignore this please if it seems im just blabbing

Posted by Neumann [send private reply] at May 08, 2003, 09:36:02 AM

Yes. Disregard whizkide comment. Buzbug is right. All you have to care about is \n.

Posted by unknown_lamer [send private reply] at May 08, 2003, 04:50:45 PM

std::getline (std::istream, std::string[, char eol]);

Reads from the istream into the string. You can specify the line delimiter as an optional third argument that defaults to '\n'.

Posted by MrSmiley [send private reply] at May 08, 2003, 06:43:12 PM

dont forget good old endl; the end line on a cout

Posted by unknown_lamer [send private reply] at May 08, 2003, 07:19:31 PM

Huh? std::endl inserts '\n' into an output stream. It has nothing to do with reading.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.