📄 11-4-4-1.cpp
字号:
#include <iostream.h>
#include <fstream.h>
void main()
{ fstream f("MYDATA", ios::in|ios::out|ios::binary);
for(int i=0; i < 10; i ++) // 写10个整数
f.write((char *)&i, sizeof(int));
streampos pos=f.tellp(); // 记下当前位置
for(i=10; i < 20; i ++) // 写10个整数
f.write((char *)&i, sizeof(int));
f.seekg(pos); // 将读指针定位到pos位置
f.read((char *)&i, sizeof(int));
cout << "The Data is:" << i << endl;
f.seekp(0, ios::beg);
for(i=100; i < 120; i ++) // 开头位置重写20个整数
f.write((char *)&i, sizeof(int));
f.seekg(pos); // 将读指针定位到pos位置
f.read((char *)&i, sizeof(int));
cout << "The Data is:" << i << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -