13.10.cpp
来自「这是C++的一部分练习程序!对初学者有一定的帮助作用。」· C++ 代码 · 共 45 行
CPP
45 行
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
class FileExcept
{
public:
FileExcept(char *s)
{
strcpy(mag,s);
// cout<<mag<<endl;
}
char *returnExpt()
{ return mag; }
private:
char mag[80];
};
void main()
{
fstream infile("abwac.txt",ios::in);
FileExcept e("Can't open file!");
try
{
if(!infile)
throw e;
}
catch(FileExcept &e)
{
cout<<"The exception is caught."<<e.returnExpt()<<endl;
abort();
}
char str[80];
while(!infile.eof())
{
infile.getline(str,sizeof(str));
cout<<str<<endl;
}
infile.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?