问题及代码:
/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:李一波
* 完成日期:2016年6月21日
* 版本号:codeblocks
*
* 问题描述:
* 输入描述:
* 程序输出:
*/
#include <fstream>
using namespace std;
int main ()
{
long pos;
ofstream outfile;
outfile.open ("test.txt");
outfile.write ("This is an apple",16);
pos=outfile.tellp();
outfile.seekp (pos-7);//把当前指针向前移动7个位置
outfile.write (" sam",4);//把 sam这占4个字节的写入this is an apple 并且把其中的字节取代
outfile.close();
return 0;
}
运行结果:
本文介绍了一个使用C++进行文件操作的例子,演示了如何在文件中写入字符串,并通过定位指针修改已写入的内容。
404

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



