为什么会显示文件"Student_Information.txt"无法打开!呢


```c++
bool Book::Personnel_System()
{
while (1)
{
int menu_options;
cout << "请输入登录密码:";
cin >> key;
if (key == "012345") //登录密码
while (1)
{
wrongAttempts = 0; // 重置错误次数
cout << endl;
cout << "——————————————" <<endl;
cout << " 登录密码输入正确!" <<endl;
cout << "——————————————" <<endl;
cout << endl;
cout<< "主菜单: " << endl;
cout<< "工作人员 " << endl;
cout<< "1——添加图书信息 "<< endl;
cout<< "2——修改图书信息" << endl;
cout<< "3——删除图书信息 "<< endl;
cout<< "4——查询图书信息" << endl;
cout<< "5——退出登录"<< endl;
cout<< "你需要做什么?(1‐5)" << endl;
cin >> menu_options;
switch (menu_options)
{
case 1:Book_add(); break;
case 2:Book_mod(); break;
case 3:Book_del(); break;
case 4:Book_search(); break;
case 5:return false;
default:cout << "输入错误,请重新选择" << endl; break;
}
if (!(menu_options == 4))
{
cout << "是否确认? 《确认/(Y/y)》 《取消/(N/n)》" << endl;
char yn;
do
{
cin >> yn;
} while (!(yn == 'Y' || yn == 'y' || yn == 'N' || yn == 'n'));
if (yn == 'Y' || yn == 'y') {
if (menu_options == 1|| menu_options == 2 || menu_options == 3)
{
B_Save_file();
}
cout << "操作成功";
}
}
B_clear();
}
else
{
cout << "密码错误!" << endl;
wrongAttempts++;
if(wrongAttempts >= 5)
{
cout << "密码错误次数已达5次,请等待倒计时结束再操作。\n";
// 启动倒计时线程
thread countdown(countdownThread);
countdown.join(); // 等待倒计时线程结束
}
continue;
}
}
return true;
}
//界面初始化函数
void login_init()
{
system("cls");
cout << "\n 欢迎进入图书管理系统1.0版" << endl;
cout << " 请输入您的登录方式" << endl;
cout << " 1 读者管理" << endl;
cout << " 2 图书管理" << endl;
cout << " 3 借阅管理" << endl;
cout << " 4 退出系统" << endl;
}
class Student
{
public:
int s_sum=0;
string key; //管理员密码
vector<Student> s_array; //记录学生类
void S_clear(); //清理已有学生信息
void S_Read_file(); //读取学生文件
void S_Save_file(); //保存学生文件
bool Student_add(); //添加学生信息
bool Student_mod(); //修改学生信息
bool Student_del(); //删除学生信息
bool Student_search();
bool Student_System(); //学生登录
bool Personnel_System(); //工作人员登录
void login_init(); //登录界面初始化
Student()
{
memset(s_num, 0, sizeof(s_num));
memset(s_name,0, sizeof(s_name));
memset(tell, 0, sizeof(tell, 0, sizeof(tell)));
borrow_max = 0;
borrow_quantity = 0;
memset(borrow_books, 0, sizeof(borrow_books));
}
char s_num[15]; //读者编号
char s_name[10]; //姓名
char tell[30]; //电话号码
int borrow_max; //最大借阅数量
int borrow_quantity; //借阅数量
char borrow_books[10][30]; //借阅图书
bool S_SetInto();
friend istream& operator>>(istream& in, Student& cp);
friend ostream& operator<<(ostream& out, Student& cp);
bool S_If_match(char p[30]);
void s_display();
void Deletenum();
};
void Student::Deletenum()
{
borrow_quantity -=0;
}
//设置学生信息
bool Student::S_SetInto()
{
char temp[15];
cout << "请输入学号:(输入+退出)";
cin >> temp;
if (temp[0] == '+')
{
return false;
}
strcpy(s_num, temp);
cout << "学生姓名:";
cin >> s_name;
cout << "电话号码:";
cin >> tell;
while (borrow_max <= 0 || borrow_max > 10)
{
cout << "最大借阅数量(1‐10):";
cin >> borrow_max;
}
return true;
}
//读取学生文件
void Student::S_Read_file()
{
ifstream s_file;
s_file.open("Student_Information.txt");
if (!s_file.is_open())
{
cerr << "文件\"Student_Information.txt\"无法打开\n";
exit(1);
}
while (!s_file.eof())
{
Student stu;
s_file >> stu;
s_array.push_back(stu);
s_sum++;
}
s_sum--;
s_file.close();
}
//保存学生文件
void Student::S_Save_file()
{
ofstream s_file("Student_Information.txt");
if (!s_file)
{
}
cerr << "文件\"Student_Information.txt\"无法打开!\n";
exit(1);
int i = -1;
while (++i < s_sum)
{
s_file << s_array[i];
}
s_file.close();
}
//添加学生信息
bool Student::Student_add()
{
S_Read_file();
Student _stu;
cout << "请进行信息录入。按“+”结束!\n";
do
{
s_array.push_back(_stu);
}
while (s_array[s_sum++].S_SetInto());
s_sum--;
s_array.pop_back();
S_Save_file();
return true;
}
bool Student::Personnel_System()
{
while (1)
{
int menu_options;
cout << "请输入登录密码:";
cin >> key;
if (key == "012345") //登录密码
while (1)
{
wrongAttempts = 0; // 重置错误次数
cout << endl;
cout << "——————————————" <<endl;
cout << " 登录密码输入正确!" <<endl;
cout << "——————————————" <<endl;
cout << endl;
cout<< " 主菜单:" << endl;
cout<< "工作人员 " << endl;
cout<< "1——添加学生信息 "<< endl;
cout<< "2——修改学生信息" << endl;
cout<< "3——删除学生信息 "<< endl;
cout<< "4——查询学生信息" << endl;
cout<< "5——退出登录"<< endl;
cout<< "你需要做什么?(1-9)" << endl;
cin >> menu_options;
switch (menu_options)
{
case 1:Student_add(); break;
case 2:Student_mod(); break;
case 3:Student_del(); break;
case 4:Student_search(); break;
case 5:return false;
default:cout << "输入错误,请重新选择" << endl; break;
}
if (!(menu_options == 4))
{
cout << "是否确认? 《确认/(Y/y)》 《取消/(N/n)》" << endl;
char yn;
do
{
cin >> yn;
} while (!(yn == 'Y' || yn == 'y' || yn == 'N' || yn == 'n'));
if (yn == 'Y' || yn == 'y')
{
if (menu_options == 1 || menu_options == 2 || menu_options == 3)
{
S_Save_file();
}
cout << "操作成功";
}
}
S_clear();
}
else
{
cout << "密码错误!" << endl;
wrongAttempts++;
if(wrongAttempts >= 5)
{
cout << "密码错误次数已达5次,请等待倒计时结束再操作。\n";
// 启动倒计时线程
thread countdown(countdownThread);
countdown.join(); // 等待倒计时线程结束
}
continue;
}
}
return true;
}
int main()
{
Book xiangnan;
Student duzhe;
management mag;
//若文件不存在,则新建文件
//存放学生信息
ofstream Student_Information("Student_Information.txt", ios::app);
if (!Student_Information)
{
cerr << "文件\"flight information.dat\"无法打开!\n";
exit(1);
}
Student_Information.close();
//存放图书信息
ofstream Book_Information("Book_Information.txt", ios::app);
if (!Book_Information)
{
cerr << "文件\"flight information.dat\"无法打开!\n";
exit(1);
}
Book_Information.close();
ofstream S_Information("S_Information.txt", ios::app);
if (!S_Information)
{
cerr << "文件\"flight information.dat\"无法打开!\n";
exit(1);
}
S_Information.close();
int dlry; //登陆人员
while (1)
{
login_init(); //界面初始化
cin >> dlry;
if (dlry == 1)
{
duzhe.Personnel_System();
}
else if (dlry == 2)
{
xiangnan.Personnel_System();
}
else if (dlry == 3)
{
mag.Student_System();
}
else if (dlry == 4)
{
return 0;
}
else
{
cout << "输入错误,请重新选择!" << endl;
}
}
return 0;
}