如果是fstream定义的对象,则seekg()和seekp()是一样的功能,还有tellp和tellg
seekg是从ifstream类里继承来的
seekp是从ofstream类继承来的
两者的功能在fstream里都是定位读写指针
char s1[30]={'\0'};
fstream f1("1.txt",ios::out);
f1<<"this is a program!\n";
f1<<"hello\n";
cout << f1.tellg()<<endl;
cout << f1.tellp()<<endl;
f1.close();
char s2[30]={'\0'};
fstream f2("1.txt",ios::in);
cout<<f2.tellg()<<endl;
cout<<f2.tellp()<<endl;
f2.seekp(-25,ios::end);
f2.getline(s1,20);
cout<<f2.tellp()<<endl;
f2.seekg(10,ios::beg);
f2.getline(s2,10);
f2.close();
cout<<s1<<endl;
cout<<s2<<endl;