#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
int main()
{
fstream io("test.txt",ios::in|ios::out|ios::trunc);
io << "abcdefg" ;
//cout << io.tellp() << endl;
io.seekp(0, ios_base::beg); // <---- 这句话是一定要的!
//cout << io.tellp() << endl;
string str1;
io >> str1;
io.close();
cout<<"Text:"<<str1<<endl;
return 0;
}
Copyright@戴维 2006.4 于北京
本文展示了一个使用C++进行文件读写的简单示例。通过fstream库实现了对文本文件的写入与读取操作,并演示了如何定位文件指针。
2076

被折叠的 条评论
为什么被折叠?



