Reseting file pointer

This is a discussion on Reseting file pointer within the C++ Programming forums, part of the General Programming Boards category; How do I reset the file pointer to the beginning of a file? Code: ifstream fin; // blahblah fin.seekg(what goes ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    63

    Reseting file pointer

    How do I reset the file pointer to the beginning of a file?
    Code:
    ifstream fin;
    // blahblah
    fin.seekg(what goes here?);
    I tried a google search, and its something like ios::beg but I couldn't get it to work.

    Thanks for the help
    -Webmaster-
    http://www.koaworld.com
    Pr0gr4m|\/|1Ng n00b

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    According to Google and "C++ ios rewind", it's this, according to the first hit:
    Code:
    fin.seekg( ios::beg );
    The second hit says to use this:
    Code:
    fin.seekg( 0, ios::beg );

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    If you have already read through the entire file in between the point in your code where you open the file and then wish to "reset the file pointer" you may be running into an issue where you need to clear any flags that may have been set (eof). Call the clear member function on the stream prior to calling the seekg member function. If you don't do this, any operations on that stream will simply not work.
    "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 major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    don't forget ios is part of the standard library, so it would actually be:
    Code:
    fin.clear();
    fin.seekg(0,std::ios::beg);
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    63
    Edit: Got it to work, reason was totally different than I had expected :P
    Last edited by Philandrew; 02-07-2005 at 05:53 PM.
    -Webmaster-
    http://www.koaworld.com
    Pr0gr4m|\/|1Ng n00b

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with file pointer in functions
    By willie in forum C Programming
    Replies: 6
    Last Post: 11-23-2008, 12:54 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM

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