/*gets the size of the data accessed in the file (in bytes) The two member functions of ELLG () and TELLP () do not pass in parameters, returning a value of type Pos_type (according to the ansi-c++ Standard), which is an integer representing the position of the current get stream pointer (with TELLG) or The position of the put stream pointer (with TELLP). SEEKG () and SEEKP () are used to change the position of the flow pointer get and put, respectively. Two functions are overloaded with two different prototypes: SEEKG (Pos_type position); SEEKP (pos_type position); Using this prototype, the flow pointer is changed to point to an absolute position from the beginning of the file. The parameter type required to pass in is the same as the return value type of the function Tellg and TELLP. SEEKG (off_type offset, seekdir direction); SEEKP (off_type offset, seekdir direction); Use this prototype to specify a specific pointer that is determined by the parameter direction Begins the calculation of a displacement (offset). It can be: Ios::beg The displacement calculated from the beginning of the flow ios::cur the displacement calculated from the current position of the flow pointer ios::end the displacement at the end of the stream*/#include<iostream>#include<fstream>using namespacestd;Const Char* Filename="a.txt";intMain () {Longl,m; Ifstream infile (filename,ios::inch|ios::binary);//establishes an input stream in binary form, associating with file A.txt//infile.seekg (0,ios::beg);//Position read pointer location for file startL=infile.tellg ();//gets the current read pointer position (in bytes)INFILE.SEEKG (0, ios::end);//Position read pointer location to end of fileM=infile.tellg ();//gets the current read pointer position (in bytes)Infile.close ();//Close Filecout<<"sizeof"<<filename; cout<<" is"<< (m-l) <<"bytes.\n"; System ("Pause");//pause for a moment return 0;}
Seek and tell usage--Get File Content size (bytes)