练习实验室 #1
Coddy C++ 文件处理 课程的第 6 课,共 23 课。
挑战
简单*不要修改不该修改的代码*
尝试打开 3 个文件:
code.txtscript.txtnovel.txt
按顺序检查是否可以打开每个文件。如果可以打开,就输出消息 File opened;否则输出 Unable to open file。
之后,只关闭文件 code.txt 和 novel.txt。
*每条消息都单独输出一行*
亲手试试
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//-------------------------
ifstream file_code;
ifstream file_script;
ifstream file_novel;
// 在这里输入你的代码
//-------------------------
// 不要修改下面的代码
if(!file_code.is_open())
cout << "File closed" << endl;
else
cout << "File still opened" << endl;
if(!file_script.is_open())
cout << "File closed" << endl;
else
cout << "File still opened" << endl;
if(!file_script.is_open())
cout << "File closed" << endl;
else
cout << "File still opened" << endl;
return 0;
}C++ 文件处理中的所有课
自己练习: C++ 在线编译器