?? 12_3.cpp
字號:
//12_3.cpp
#include<iostream>
#include<fstream> //包含文件流頭文件
#include"employee.h"
using namespace std;
class FileException { //文件異常處理類
public:
FileException()
: message( "File is not created!" ) { }
const char *what() const { return message; }
private:
const char *message;
};
int main()
{
ifstream infile("employee.txt",ios::in); //創建一個輸入文件流對象
try {
if (!infile)
throw FileException(); //拋出異常
}
catch ( FileException fe ) // 捕捉異常
{
cout<<fe.what()<<endl; //輸出異常
exit(0); //退出程序
}
cout<<"從文件中讀取信息并顯示如下:"<<endl;
//從文件讀入人員信息
char line[101];
for(int i=0;i<4;i++)
{
infile.getline(line,100);
cout<<line<<endl;
}
infile.close();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -