📄 randfil1.cpp
字号:
//这个程序在本书所带软盘中,文件名为RANDFIL1.CPP
//这个程序演示随机文件访问的操作。
#include <fstream.h>
void main(void)
{
char ch;
long offset, last, noff;
fstream in_file("test.txt", ios::in);
if (!in_file) //检查文件打开操作是否成功
{
cout << "\n打开文件操作错误。检查文件盘后再试..." << endl;
return; //停止程序运行,也可以写作exit(1);
}
in_file.seekg(0L, ios::end); //将文件指针指向文件尾
last = in_file.tellg(); //将文件指针的位置赋予变量last暂存
for(offset = 1L; offset <= last; offset++)
{
in_file.seekg(-offset, ios::end);
ch = in_file.get();
cout << ch << " _ ";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -