第十四周阅读程序(7):对二进制文件操作
来源:互联网 发布:江苏减招事件知乎 编辑:程序博客网 时间:2024/06/09 16:34
代码:
#include <iostream>#include <fstream>using namespace std;int main(){ ifstream readFile; ofstream writeFile; char ch; readFile.open("a.txt", ios::in); writeFile.open("b.txt", ios::out); while (readFile.get(ch)) writeFile.put(ch); readFile.close(); writeFile.close(); cout << "Finish!" << endl; return 0;}
运行结果:
代码:
#include <iostream>#include <fstream>#include<cstring>using namespace std;int main(){ ifstream readFile; ofstream writeFile; char ch[100]; readFile.open("a.txt", ios::in); writeFile.open("b.txt", ios::out); while (!readFile.eof()) { readFile.getline(ch,100,'\n'); writeFile.write(ch,strlen(ch)); writeFile.write("\n",1); } readFile.close(); writeFile.close(); cout << "Finish!" << endl; return 0;}
运行结果:
学习心得:
用成员函数readFile,writeFile读写二进制文件。while (!readFile.eof())表示readFile.eof()为假表示未遇到文件结束符。
0 0
- 第十四周阅读程序(7):对二进制文件操作
- 第十四周阅读程序(5):对数据文件的操作与文件流
- 第十四周阅读程序
- 第十四周 阅读程序
- 第十四周程序阅读
- 第十四周--阅读程序
- 第十四周阅读程序
- 第十四周阅读程序
- 第十四周项目六 阅读程序(7、8、9)
- 第十四周项目六 阅读程序 (7)
- 第十四周:阅读程序1-(1)
- 第十四周阅读程序:1-(2)
- 第十四周阅读程序:1-(3)
- 第十四周 阅读程序(1)
- 第十四周 阅读程序 (2)
- 第十四周:阅读程序(2)
- 第十四周程序阅读(2)
- 第十四周阅读程序(1)
- 通过电影有效速记GRE词汇方法之从听力突破口语语音
- 跨服务器访问数据库
- ECShop在PHP 5.4以上版本报错的解决
- (我总结的实用主义)Loadrunner运行常见错误
- 双向链表的一个C++实现
- 第十四周阅读程序(7):对二进制文件操作
- hdu5247找连续数(打表)
- Android设置Selector不同状态下颜色及图片
- OGNL使用方法总结
- SAT数学练习题一道
- 使用代码绘制一个电池 (非图片)
- HDU1598 并查集 或 二分+DFS
- Android九宫格解锁的实现
- APP4Smarthome项目总结1