ifstream

V

vw_bora

Hi

I am using ifstream to read the contents of a file using getline(). I
would like to determine the line number of the file that the getline()
is reading. However, lookinfg at the istream API

http://www.cplusplus.com/reference/iostream/ifstream/

I can't see how it's possible to get the line number.
Anybody have a suggestion that I can use ?

Thank you.

Pete
 
G

Gene

Hi

I am using  ifstream to read the contents of a file using getline(). I
would like to determine the line number of the file that the getline()
is reading. However, lookinfg at the istream API

http://www.cplusplus.com/reference/iostream/ifstream/

I can't see how it's possible to get the line number.
Anybody have a suggestion that I can use ?

You'll have to keep track of the line number yourself. One way to do
this is with a wrapper class for ifstream.
 
F

Flash Gordon

Hi

I am using ifstream to read the contents of a file using getline(). I

<snip>

In that case you are not using C. C++ and C are different languages, if
you are using C++ I suggest asking in comp.lang.c++ where you will find
C++ programmers.
 
A

Antoninus Twink

I am using ifstream to read the contents of a file using getline(). I
would like to determine the line number of the file that the getline()
is reading. However, lookinfg at the istream API I can't see how it's
possible to get the line number.

You're right - the API doesn't provide it. You need to read the file
from the beginning and keep track of the line number yourself.
 
V

vw_bora

<snip>

In that case you are not using C. C++ and C are different languages, if
you are using C++ I suggest asking in comp.lang.c++ where you will find
C++ programmers.

Hi
Bit late but just like to thank Gene & Antoninus for their suggestion
which I used successfully.

Thank You.
Pete.
 
O

Old Wolf

You're right - the API doesn't provide it. You need to read the file
from the beginning and keep track of the line number yourself.

Come on, let's have your self-righetous spiel about
how brilliant and considerate you are for responding
to the off-topic post, and about how the other
respondants are pedantic, mentally ill, and should be sued..
 

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

Similar Threads

Rearranging .ply file via C++ String Parsing 0
TF-IDF 1
ifstream::getline() synatx 18
Error with ifstream and exceptions 71
ifstream errors 15
Deriving from ifstream 3
ifstream speed 3
Crossword 2

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top