//**********************************************************************************************************
//*程序作者:冰糖
//*完成日期:2019年3月22日
//*章 节:第二章
//*题 号:2
//*题 目:编写一个程序,要求用户输入文件名,在屏幕上显示文件的内容。
//* 如果一屏显示不完文件的内容,那么显示24行后,暂停一下,等待用户按任意键以后继续显示后面的24行。
//* 注:先采用编辑器(如记事本)创建一个文本文件,以测试这个程序。
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char fileName[20];
char buf[200];
int count=0;
fstream datafile;
cout<<"请输入文件名:"<<endl;
cin>>fileName;
datafile.open(fileName,ios::in);
//datafile.open("number.txt",ios::in);
if(!datafile)
{
cout<<"打开文件失败!"<<endl;
exit(0);
}
while(datafile.eof()==false)
{
datafile.getline(buf,81);
cout<<buf<<endl;
count++;
if(count%24==0)
system("pause");
}
datafile.close();
return 0;
}
number.txt:
11111
22222
333number 33
44444
55555
66666
77777
88888
99999
101010
111111
121212
131313
1414
1515
1616
1717
1818
1919
2020
21
22
23
24
25
26
27
28
29
30