identifying end of line while reading data from an ifstream

O

omariqbalnaru

Is there any way to identify end of line while reading data from an
ifstream?
 
R

Rolf Magnus

omariqbalnaru said:
Is there any way to identify end of line while reading data from an
ifstream?

Use std::getline to read. It automatically stops at the end of a line.
 
S

Salt_Peter

omariqbalnaru said:
Is there any way to identify end of line while reading data from an
ifstream?

std::getline does that for you. It'll read lines into your buffer until
failure due to eof. The ifstream even has a bit flag to indicate that
eof is the reason the input file stream stopped . Which is nice cause
you can check for non-eof failure-conditions with if(!ifs.eof()) {...}.
 
D

David Harmon

On 23 Nov 2006 10:38:31 -0800 in comp.lang.c++, "omariqbalnaru"
Is there any way to identify end of line while reading data from an
ifstream?

Can be tricky, depending on just how perverse your input can be.
But, a construct like
if (cin.peek() == '\n')
can sometimes be useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top