1#include <iostream>2#include <fstream>3#include <cassert>4 5 using namespacestd;6 intMain ()7 {8Ifstreaminch("Test_data.txt");9Assertinch. Is_open ());Ten One //The base address is at the end of the file with an offset of 0, so the pointer is positioned at the end of the file A inch. SEEKG (0, ios::end); - //The SP is a positional pointer because it is at the end of the file, so that is the size of the file -Streampos SP =inch. TELLG (); thecout<<"File Size:"<<sp<<Endl; - - //base Address is the end of the file, the offset address is negative, so move forward Sp/3 bytes - inch. SEEKG (-sp/3, Ios::end); +Streampos SP2 =inch. TELLG (); -cout<<"From file to point :"<<sp2<<Endl; + A //base Address is the file header, the offset is 0, so locate in the file header; Read the contents of the file from the beginning at inch. SEEKG (0, Ios::beg); -cout<<inch. RDBUF () <<endl;//All the contents of all output files due to the offset from the beginning - - //read the contents of the file from SP2, i.e. everything behind SP2 - inch. SEEKG (SP2); -cout<<inch. RDBUF () <<Endl; in - inch. Close (); to + return 0; -}
C + + file offset