Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Read a text file

Reply
Thread Tools

Read a text file

 
 
Claudio Varini
Guest
Posts: n/a
 
      02-19-2004
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,
 
Reply With Quote
 
 
 
 
Sharad Kala
Guest
Posts: n/a
 
      02-19-2004

"Claudio Varini" <(E-Mail Removed)-bielefeld.de> wrote in message
news:(E-Mail Removed)-bielefeld.de...
> 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-lit....html#faq-15.5


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      02-20-2004
Claudio Varini wrote:

> while(!Store.eof()) {
> Store >> a >> b >> c;
> }


while(Store >> a >> b >> c);

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
file.read() doesn't read the whole file Sreejith K Python 24 03-24-2009 12:20 PM
read a ruby script like you would read a text file Mmcolli00 Mom Ruby 2 01-27-2009 10:52 PM
In file parsing, taking the first few characters of a text file after a readfile or streamreader file read... .Net Sports ASP .Net 11 01-17-2006 12:44 AM
Read Text File and split them to individual text file Krish ASP .Net 1 10-20-2005 03:39 PM



Advertisments