第十六周项目一 d阅读程序(2)
2016-06-10 19:02
197 查看
/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:舒文超 * 完成日期:2016年6月10日 * 版本号:vc++6.0 * 问题描述:阅读下面的程序,指出其功能,体会seekg()、 tellg()等函数的功能及其用法 */ #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; }
运行结果:(这是文件中写入的)
解释:seekp()与tellp是差不多的。当用于读取一个文件,并要知道内置指针的当前位置时,应该使用tellg();
当用于写入一个文件,并要知道内置指针的当前位置时,应该使用tellp()。
相关文章推荐
- 20160609常规赛总结
- Android XML解析
- SNMP
- Java中常见编码格式
- SlidingMenu的配置
- Android App解决卡顿慢之内存抖动及内存泄漏(发现和定位)
- Score(模拟)uva1585
- Android多线程性能优化(二)
- Java中对多线程的认识
- 分享常见的DOM事件
- ELF文件的加载过程(load_elf_binary函数详解)--Linux进程的管理与调度(十三)
- [Mac][MySQL]如何启动MySQL Server
- nyoj 19 擅长排列的小明 【next_permutation() 】
- 单表查询查询所有字段
- MFC中屏蔽ESC和回车关闭对话框
- 限制波尔兹曼机
- 一维动态规划和二维动态规划中两道经典题目
- ContentProvider读写联系人列表以及权限处理
- Andoird Crash的跟踪方法,使用腾讯Bugly来捕捉一些疑难杂症,让我们APP稳定上线
- Andoird Crash的跟踪方法,使用腾讯Bugly来捕捉一些疑难杂症,让我们APP稳定上线