一、代码
fstream
seekp()、seekg()
tellp()、tellg()
1.1 文件template.c
需要事先准备好的文件内容:
wc -c template.c
1.2 代码
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;
//fstream
//seekp()、seekg()
//tellp()、tellg()
int main(int argc, char*argv[])
{
//
ifstream ifs("template.c");
assert(ifs);
ifs.seekg(0, ios::end);
streampos n = ifs.tellg();
cout<<"file len: "<<n<<endl;
ifs.close();
//
fstream fs;
fs.open("template.c", ios::in);
assert(fs.is_open());
//fs.seekp(0, ios::end);
//n = fs.tellp();
fs.seekg(0, ios::end);
n = fs.tellg();
cout<<"file len: "<<n<<endl;
fs.close();
return 0;
}
二、输出结果