11-4-4-1.cpp
来自「学习c++的ppt」· C++ 代码 · 共 20 行
CPP
20 行
#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 + =
减小字号Ctrl + -
显示快捷键?