going back to the top line in input file

Discussion in 'C++' started by mahurshi@gmail.com, Nov 12, 2005.

  1. Guest

    i am reading a file like this

    ifstream infile(somefilenamestring.c_str())

    while (infile >> myvariable)
    {
    /* do some interesting stuff */
    }

    now... if i want to get back to the first line of the file after i
    executed this loop, what should i do ? is there a special thing that
    needs to be done?
    , Nov 12, 2005
    #1
    1. Advertising

  2. John Ratliff Guest

    wrote:
    > i am reading a file like this
    >
    > ifstream infile(somefilenamestring.c_str())
    >
    > while (infile >> myvariable)
    > {
    > /* do some interesting stuff */
    > }
    >
    > now... if i want to get back to the first line of the file after i
    > executed this loop, what should i do ? is there a special thing that
    > needs to be done?
    >


    You could use seekg.

    --John Ratliff
    John Ratliff, Nov 12, 2005
    #2
    1. Advertising

  3. red floyd Guest

    John Ratliff wrote:
    > wrote:
    >
    >> i am reading a file like this
    >>
    >> ifstream infile(somefilenamestring.c_str())
    >>
    >> while (infile >> myvariable)
    >> {
    >> /* do some interesting stuff */
    >> }
    >>
    >> now... if i want to get back to the first line of the file after i
    >> executed this loop, what should i do ? is there a special thing that
    >> needs to be done?
    >>

    >
    > You could use seekg.


    Don't forget to call clear() before seekg().
    red floyd, Nov 12, 2005
    #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. Maziar Aflatoun
    Replies:
    1
    Views:
    351
    =?Utf-8?B?bG9uZG9uIGNhbGxpbmc=?=
    Jul 5, 2005
  2. Adrian
    Replies:
    29
    Views:
    899
  3. scad
    Replies:
    23
    Views:
    1,146
    Alf P. Steinbach
    May 17, 2009
  4. Mike Owen

    Stop page going back to the top when submitting

    Mike Owen, Nov 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    8
    Views:
    236
    Steven Cheng[MSFT]
    Nov 9, 2005
  5. GreenLeaf
    Replies:
    3
    Views:
    129
    Tad McClellan
    Feb 24, 2005
Loading...

Share This Page