11_92.cpp

来自「C++程序设计技能百练随书配套光盘的源码」· C++ 代码 · 共 33 行

CPP
33
字号
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{
	int r;	char c;
	fstream file;
	char fn[15],buf[100];
	cout<<"Input the file'name:";
	cin>>fn;
	file.open(fn,ios::nocreate|ios::in);  
	//针对文件后缀为(.txt  .h  .cpp .pas等)文件
	if(!file)
	{
		cout<<"The file you wanted open does NOT exist.";
		abort();  //#include<stdlib.h>
	}
	while(!file.eof())
	{
		r=0;
		while(!file.eof() && r<23)
		{
			file.getline(buf,100);
			cout<<buf<<endl;
			r++;
		}
		cout<<"press 'enter' key...";
		c=getchar();  //#include<stdio.h>
	}
	file.close();
}

⌨️ 快捷键说明

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