当前位置:网站首页>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();
边栏推荐
- Redirection of redis cluster
- 13. (map data) conversion between Baidu coordinate (bd09), national survey of China coordinate (Mars coordinate, gcj02), and WGS84 coordinate system
- 2022年国内云管平台厂商哪家好?为什么?
- Course design of compilation principle --- formula calculator (a simple calculator with interface developed based on QT)
- Codeforces Round #804 (Div. 2)
- Pytorch weight decay and dropout
- 调查显示传统数据安全工具在60%情况下无法抵御勒索软件攻击
- Linux Installation and deployment lamp (apache+mysql+php)
- The survey shows that traditional data security tools cannot resist blackmail software attacks in 60% of cases
- Codeforces Round #804 (Div. 2)
猜你喜欢
Troubleshooting of high memory usage of redis in a production environment
splunk配置163邮箱告警
Redis集群的重定向
报错ModuleNotFoundError: No module named ‘cv2.aruco‘
【云原生 | Kubernetes篇】Ingress案例实战(十三)
Matlab imoverlay function (burn binary mask into two-dimensional image)
石油化工企业安全生产智能化管控系统平台建设思考和建议
Reading notes of growth hacker
liunx禁ping 详解traceroute的不同用法
Network five whip
随机推荐
What is digital existence? Digital transformation starts with digital existence
Error modulenotfounderror: no module named 'cv2 aruco‘
Time tools
The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
liunx禁ping 详解traceroute的不同用法
[calculation of loss in yolov3]
语义分割实验:Unet网络/MSRC2数据集
Shell script file traversal STR to array string splicing
XML解析
Wireless WiFi learning 8-channel transmitting remote control module
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
How to protect user privacy without password authentication?
【yolov3损失函数】
【使用TensorRT通过ONNX部署Pytorch项目】
Pytorch MLP
Simply solve the problem that the node in the redis cluster cannot read data (error) moved
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
Hiengine: comparable to the local cloud native memory database engine
Open3D 欧式聚类
[upsampling method opencv interpolation]