Thread: Reseting file pointer

  1. #1
    Registered User
    Join Date
    Oct 2004

    Reseting file pointer

    How do I reset the file pointer to the beginning of a file?
    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
    Pr0gr4m|\/|1Ng n00b

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

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    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
    don't forget ios is part of the standard library, so it would actually be:
    Join is in our Unofficial Cprog IRC channel
    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
    Edit: Got it to work, reason was totally different than I had expected :P
    Last edited by Philandrew; 02-07-2005 at 06:53 PM.
    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, 01: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