C++文件的读写
来源:互联网 发布:数据审计追踪 编辑:程序博客网 时间:2024/06/06 02:43
/主要采用iostream和fstream两个库来进行。其中fstream下面有ifstream表示读取文件打印到屏幕上,ostream表示将数据写到文件上。下面是一个案列:/
/*通过c++的iostream和fstream来读写文件*/#include"stdio.h"#include"iostream"#include"fstream"using namespace std;int main(){ //声明一个对象来写数据 ofstream outfile; //这里采用头文件fstream所包含的ofstream和ifstream //声明一个字符数组来存放数据 char data[100];//这里app代表append,如果不加则每次都重新建立文件,把前面的内容清空,app则在文件后面追加 cout << "writing to the file..." << endl; cout << "please input your name:" << endl;// cin.getline(data, 100); //获得输入的一行// cin >> data; int fun(); outfile << fun() << endl;//关闭文件,这个一定要记住 outfile.close();//读取文件并且输出//声明读取对象infile,类型是ifstream ifstream infile; infile.open("cc_file.dat"); cout << "reading the file now...." << endl; //读取文件所有行内容 //for(int i=0;i<infile.) while(!infile.eof()){ //把文件内容传给data infile >> data; cout << data << endl; } return 0;}//main()函数内部声明,函数外定义。int fun() { int x, y; cout << "please input x:" << endl; cin >> x; cout << "please intpu y:" << endl; cin >> y; return x + y;}
0 0
- C文件的读写
- C文件的读写
- 【C#】系统配置文件的读写
- C语言文件的读写
- C语言的文件读写
- C语言的文件读写
- C语言 文件的读写
- C语言文件的读写
- C对文件的读写
- C语言文件的读写
- C文件之三 文件的读写
- C语言文件操作----文件的读写
- 【C/C++】文件读写
- Unicode 文件的读写(C)
- C/C++的文件读写操作
- C读写文件--删除指定的一行
- C的文件打开关闭与读写
- C#: 最简单的文件读写
- Redis的分片、预分片技术总结
- codeforces No to Palindromes!(字符串处理,不能有回文)
- 2016多校联合第二场 HDU5739 Fantasia 解题报告
- java使用ajax实现进度条
- hdoj 1085 Holding Bin-Laden Captive! <思维>
- C++文件的读写
- Informix11.70培训笔记(3)
- 数据库基础知识
- 连载:面向对象葵花宝典:思想、技巧与实践(14) - 面向对象开发技术流程
- Golang1.7使用ICMP协议实现ping功能,带TIME和TTL
- 怎样提高程序员的软实力,走上人生巅峰(http://bbs.jointforce.com/topic/17845?ref=myread)
- 03智力题
- 关于iOS生命周期和前后台的切换
- Informix11.70培训笔记(4)