Read a text file

Discussion in 'C++' started by Claudio Varini, Feb 19, 2004.

  1. 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,
    Claudio Varini, Feb 19, 2004
    #1
    1. Advertising

  2. Claudio Varini

    Sharad Kala Guest

    "Claudio Varini" <-bielefeld.de> wrote in message
    news:-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-lite/input-output.html#faq-15.5
    Sharad Kala, Feb 19, 2004
    #2
    1. Advertising

  3. Claudio Varini

    Rolf Magnus Guest

    Claudio Varini wrote:

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


    while(Store >> a >> b >> c);
    Rolf Magnus, Feb 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krish
    Replies:
    1
    Views:
    1,060
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Oct 20, 2005
  2. Sreejith K
    Replies:
    24
    Views:
    986
    Sreejith K
    Mar 24, 2009
  3. Mmcolli00 Mom
    Replies:
    2
    Views:
    186
    Mmcolli00 Mom
    Jan 27, 2009
  4. Alex Dowad
    Replies:
    4
    Views:
    257
    Michel Demazure
    May 1, 2010
  5. Replies:
    19
    Views:
    232
    Andreas Perstinger
    Oct 7, 2013
Loading...

Share This Page