11_27.cpp

来自「C++语言程序设计案例教程,郑莉编的书」· C++ 代码 · 共 20 行

CPP
20
字号
#include <iostream>
#include <fstream>
using namespace std;
void main()
{	char ch;
	fstream file;	file.open("zrf.dat",ios::out|ios::in|ios::binary);
	if  (!file)	{	cout << "can not open zrf.dat"<< endl; abort(); }
	for(int i=1;i<3;i++)
	{	file<<i;
		//输出文件指针位置
		cout  << "During inputing, the input position is:"<<file.tellp()<<endl;
	}
	file.seekg(0,ios::beg);		//定位到文件头
	while  (!file.eof())
	{	file.get(ch);
		//输出文件指针位置
		cout  << "During outputing, the output position is:" << file.tellg()<<endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?