您的位置:首页 > 其它

第十六周阅读项目-8

2016-06-12 12:36 127 查看
/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:刘涛
* 完成日期:2016年6月11日
* 版本号:vc++6.0
* 问题描述:阅读程序
*/

#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);
outfile.write (" sam",4);
outfile.close();
return 0;
}

运行结果:



定义一个输出流文件,然后用open函数打开,write函数把一个内存中的一块内容写到一个文件输出流中,长度参数指出写的字节数。pos返回当前指针的位置,然后往前移动7位,app就被sam代替。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: