Read a text file

C

Claudio Varini

Hallo,
I have a text file (that I call Text_File) with the following values
written inside:

2 34 5
2 32 43
56 534 69

If I want to read each line and convert the numbers into integer
I use this code:

int a,b,c;
ifstream Store("Text_File")
while(!Store.eof()) {
Store >> a >> b >> c;
}


In this way I read two times the last line of the text file, and I would
like to avoid it.

Does anyone know a solution which reads the last line only once?

Thanks,
 
S

Sharad Kala

Claudio Varini said:
Hallo,
I have a text file (that I call Text_File) with the following values
written inside:

2 34 5
2 32 43
56 534 69

If I want to read each line and convert the numbers into integer
I use this code:

int a,b,c;
ifstream Store("Text_File")
while(!Store.eof()) {
Store >> a >> b >> c;
}


In this way I read two times the last line of the text file, and I would
like to avoid it.

Does anyone know a solution which reads the last line only once?

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top