镇海官方网站建设,网站推广的步骤,网站建设及维护干什么的,wordpress 单栏 宽屏c++流
IO :向设备输入数据和输出数据
C++的IO流
设备: 文件控制台特定的数据类型(stringstream)c++中,必须通过特定的已经定义好的类, 来处理IO(输入输出) 文件流
文件流: 对文件进行读写操作
头文件:
类库:
ifstream 对文件输入(读文件)
ofstream 对文件输出(写…c++流
IO :向设备输入数据和输出数据
C++的IO流
设备:
文件控制台特定的数据类型(stringstream)c++中,必须通过特定的已经定义好的类, 来处理IO(输入输出) 文件流
文件流: 对文件进行读写操作
头文件:
类库:
ifstream 对文件输入(读文件)
ofstream 对文件输出(写文件)
fstream 对文件输入或输出
对文本流读写
模式标志描述ios::in读方式打开文件ios:out写方式打开文件ios::trunc如果此文件已经存在, 就会打开文件之前把文件长度截断为0ios::app尾部最加方式(在尾部写入)ios::ate文件打开后, 定位到文件尾ios::binary二进制方式(默认是文本方式)以上打开方式, 可以使用位操作 | 组合起来
###写文本文件 #include iostream#include fstream//流 #include string#include stdlib.husing namespace std;int main(void) {//ofstream Outfile;//写fstream Outfile;//可读可写Outfile.open("user.txt",ios::out|ios::trunc);string name;int age;while (true){cout "请输入姓名:[ctrl + z 退出]" endl;cin name;if (cin.eof()) {break;}Outfile name"\t";//写入文件cout "请输入年龄:";cin age;Outfile age endl;}//关闭打开的文件Outfile.close();}
读文本文件
#include fstream
#include iostream
#include stringusing namespace std;int main()
{string name;int age;ifstream infile;infile.open("user.txt");while (1) {infile name;if (infile.eof())