Thread: So how do I get an ifstream to start at the top of the file again?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question So how do I get an ifstream to start at the top of the file again?

    So how do I get an ifstream object to start at the top of the file again, if its already read some lines with getline() and/or is already at the end of the file?
    I'm using the global getline() function which has a prototype of the following:

    Code:
    istream& getline ( istream& is, string& str );
    I tried calling ios::clear() before the getline call, but it didn't work. The ifstream object is still at the end of the file after the call to ifstream_object_name.clear().
    After attempting that, and it not working, I went and looked at the reference to ios::clear(), and learned it only clears the error flags. It doesn't reset the input filestream to the top of the file, unfortunately. So how do I do that?
    Last edited by Programmer_P; 01-23-2011 at 10:57 AM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM