Go to the begining of file (new one)

This is a discussion on Go to the begining of file (new one) within the C++ Programming forums, part of the General Programming Boards category; if i write c++ like this code, write the value to file. Then,how can i set the pointer back to ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    4

    Unhappy Go to the begining of file by same pointer

    if i write c++ like this code, write the value to file.
    Then,how can i set the pointer back to the beginning of file that i have just written it.

    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    	int a = 10;
    
    	fstream aTa("Data_Check.txt",ios::out);
    	for(int i=0;i<a;i++0)
    		aTa << i;
    
    	return 0;
    }
    Last edited by Downnin; 08-27-2005 at 02:28 PM.

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    For writing, use seekp.

    Code:
    aTa.seekp( 0, ios_base::beg );
    For reading, use seekg.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  3. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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