当前位置:网站首页>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();
边栏推荐
- Embedded software architecture design - message interaction
- 嵌入式软件架构设计-消息交互
- 【load dataset】
- ACID事务理论
- Liunx prohibit Ping explain the different usage of traceroute
- Use and install RkNN toolkit Lite2 on itop-3568 development board NPU
- [yolov3 loss function]
- How to make your products as expensive as possible
- [pytorch pre training model modification, addition and deletion of specific layers]
- 【load dataset】
猜你喜欢
redis主从模式
查看rancher中debug端口信息,并做IDEA Remote Jvm Debug
redis主从中的Master自动选举之Sentinel哨兵机制
Embedded software architecture design - message interaction
Wireless WiFi learning 8-channel transmitting remote control module
【无标题】
Splunk configuration 163 mailbox alarm
splunk配置163邮箱告警
【 YOLOv3中Loss部分计算】
How to clear floating?
随机推荐
强化学习-学习笔记3 | 策略学习
《看完就懂系列》15个方法教你玩转字符串
[pytorch pre training model modification, addition and deletion of specific layers]
Halcon template matching actual code (I)
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
谜语1
【云原生 | Kubernetes篇】Ingress案例实战(十三)
12.(地图数据篇)cesium城市建筑物贴图
Open3D 网格(曲面)赋色
Hiengine: comparable to the local cloud native memory database engine
【yolov3损失函数】
【PyTorch预训练模型修改、增删特定层】
yolov5目標檢測神經網絡——損失函數計算原理
View all processes of multiple machines
XML parsing
【Win11 多用户同时登录远程桌面配置方法】
[untitled]
July Huaqing learning-1
程序员内卷和保持行业竞争力