istream question

This is a discussion on istream question within the C++ Programming forums, part of the General Programming Boards category; is there a way to set the istream back to the begining of the file?...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    14

    istream question

    is there a way to set the istream back to the begining of the file?

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    14
    my appologies, i meant ifstream, and i think seekg may be the answer, but i have got to go out, i will post my result for any who are interested.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Yes, use seekg but you will likely also need to use clear first.

    Code:
    ifstream input;
    string data;
    
    // Read until end of stream
    
    do
    {
        getline(input,data);
        // Do stuff
    } while( !input.eof() );
    
    // Seek back to beginning of stream
    
    input.clear();
    input.seekg(0L,ios::beg);
    
    // Do more stuff with input stream
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    14
    my friend, thank you for the pointer on Clear().... you saved me from redesigning a vb interface at the last minute.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. istream question
    By dnguyen1022 in forum C++ Programming
    Replies: 7
    Last Post: 04-15-2009, 09:30 AM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. istream question
    By lord in forum C++ Programming
    Replies: 8
    Last Post: 11-13-2008, 03:31 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21