当前位置:网站首页>Xi IO flow
Xi IO flow
2022-07-05 12:08:00 【Banyuanjun 578】
One Concept
One The concept of flow
Unstructured transmission of data
C++ flow ( External input computer , Computer output external , The process of input and output )
C++11 standard :I/O Standard class library
/* I: in Input O: out Output flow : Data flow */
Two Use
fstream Common file operations class
One Common member functions
01 Open file open
| Pattern mark | Applicable to | effect |
|---|---|---|
| ios::in | ifstream fstream | Open file for reading data . If the file doesn't exist , Then there is an error opening |
| ios::out | ofstream fstream | Open file for writing data . If the file doesn't exist , Then create a new file ; If the file exists originally , The original content is cleared when it is opened |
| ios::app | ofstream fstream | Open file , Used to add data at the end . If the file doesn't exist , Then create a new file |
| ios::ate | ifstream | Open an existing file , And will File read pointer Point to the end of the file . If the file doesn't exist , Then there is an error opening |
| ios::trunc | ofstream | When the file is opened, all data stored inside will be emptied , When used alone with ios::out identical |
| ios::binary | ifstream ofstream fstream | Open the file in binary mode . If this mode is not specified , Open... In text mode |
| ios::in | ios::out | fstream | Open an existing file , You can read its contents , You can also write data to it . When the file was first opened , The original content remains unchanged , If the file doesn't exist , Then there is an error opening |
| ios::in | ios::out | ofstream | Open an existing file , Data can be written to it . When the file was first opened , The original content remains unchanged , If the file doesn't exist , Then there is an error opening |
| ios::in | ios::out | ios::trunc | fstream | Open file , You can read its contents , You can also write data to it . If the file doesn't exist , Then create a new file ; If the file exists originally , The original content is cleared when it is opened |
02 Operation file
//1. Judge whether the file is opened successfully
obj.is_open();// Return value
//2. Whether to reach the end of the file
obj.eof();// Return value
//3. write in ️ One character
obj.put('s');
//4. Read ️ One character
char ch = 0;
obj.get(ch);
ch = obj.get();
//5. Move file pointer
/* Parameters : Moving distance , Where to start moving */
/*
1 ios::beg Beginning of file
2 ios::end End of file
3 ios::cur The current position
*/
obj.seekp(2, ios::cur);
//6. Binary read-write file Large and small end storage
/* Write write */
obj.open("test.txt",ios::out);
int num = 0X11223344;
obj.write((const char*)&num,sizeof(int));
obj.close();
/* read read */
obj.open("test.txt",ios::in);
int val = 0;
obj.read((char*)&val,sizeof(int));
obj.close();
cout << hex << "val = 0X-" << val << endl;03 Close file close
3、 ... and Using overloaded << >>
obj.open("test.txt",ios::out);
obj << "HAPPY NEW YEAR!" << endl;
obj << " May you be happy and prosperous " << endl;
obj << "10086" << endl; //
obj.close();
obj.open("test.txt",ios::in);
char str_1[128];
char str_2[128];
int num;
obj >> str_1 >> str_2 >> num >> endl;
obj.close();边栏推荐
猜你喜欢

How to protect user privacy without password authentication?

redis 集群模式原理
![[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]](/img/ad/b96e9319212cf2724e0a640109665d.png)
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]

全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀

【无标题】

12.(地图数据篇)cesium城市建筑物贴图

【Win11 多用户同时登录远程桌面配置方法】

Linux安装部署LAMP(Apache+MySQL+PHP)

Pytorch weight decay and dropout

多表操作-自关联查询
随机推荐
liunx禁ping 详解traceroute的不同用法
【无标题】
[configuration method of win11 multi-user simultaneous login remote desktop]
Application of a class of identities (vandermond convolution and hypergeometric functions)
vscode快捷键
Matlab imoverlay function (burn binary mask into two-dimensional image)
Recyclerview paging slide
XML parsing
Multi table operation - sub query
【Win11 多用户同时登录远程桌面配置方法】
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
1个插件搞定网页中的广告
强化学习-学习笔记3 | 策略学习
Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)
多表操作-子查询
Reinforcement learning - learning notes 3 | strategic learning
How to protect user privacy without password authentication?
Yolov5 target detection neural network -- calculation principle of loss function
石油化工企业安全生产智能化管控系统平台建设思考和建议
yolov5目标检测神经网络——损失函数计算原理