思维导图:(我是根据这个图做的,自己可能思路没这么清楚,这里建议大家写代码的时候也先进行构思,因为这是一个很好的习惯,写好思维导图之后,写代码按照功能一块一块填好就行了,这里用到了多态,容器,以及一些基本的c++功能,因为最近就在学这些,然后就实践一下,感觉c++的面对对象编程在思路上的确比c的面对过程编程要稍微显得清晰一些,嗯,可能分的块更加清晰了把。分文件的编写会让条理更加清晰。) 所有文件如下: 这里将管理员,教师和学生分为3个子类,父类是一个包含他们公共信息的identity类,可以将他们的共性放在里面,然后个性写在子类里就行了,父类是写了个虚函数,所以子类里面一定要重载,最后按功能填写代码就行了,这里注意文件打开后要进行close,一些小细节就不说了下面上代码。 头文件: Identity.h(身份类头文件)
//身份基类头文件 #pragma once #include<iostream> using namespace std; class Identity { public: virtual void operMenu() = 0;//纯虚函数,子类重写 string m_Name;//姓名 string m_Pwd;//密码 };manager.h(管理员头文件)
#pragma once #include<iostream> using namespace std; #include"Identity.h" #include<string> #include"globalFile.h" #include<fstream> #include"student.h" #include"teacher.h" #include<vector> #include<algorithm> #include"computerRoom.h" class Manager:public Identity { public: //默认构造函数 Manager(); //有参构造函数 Manager(string name, string pwd); //菜单界面 virtual void operMenu(); //添加账号 void addPerson(); //查看账号 void showPerson(); //查看所有机房 void showComputer(); //清空预约记录 void cleanFile(); //初始化容器 void initVector(); //学生容器 vector<Student> vstu; //教师容器 vector<Teacher> vtea; bool checkRepect(int id, int type); vector<computerRoom> vcom; };student.h(学生类头文件)
#pragma once #include<iostream> using namespace std; #include"Identity.h" #include<string> #include<vector> #include"computerRoom.h" #include<fstream> #include"globalFile.h" #include"orderFile.h" //学生类 class Student:public Identity { public: //默认构造函数 Student(); //有参构造函数 Student(int id,string name,string pwd); //菜单界面 virtual void operMenu(); //申请预约 void applyOrder(); //查看预约 void showMyOrder(); //查看所有人预约 void showAllOrder(); //取消预约 void cancelOrder(); //学生学号 int m_Id; //机房容器 vector<computerRoom> vcom; };teacher.h(教师类头文件)
#pragma once #include<iostream> using namespace std; #include"Identity.h" #include<string> #include"orderFile.h" #include<vector> //教师类 class Teacher:public Identity { public: //默认构造函数 Teacher(); //有参构造函数 Teacher(int empid, string name, string pwd); //子菜单 virtual void operMenu(); //查看所有预约 void showAllOrder(); //审核预约 void vaildOrder(); //职工号 int EmpId; };globalFile.h(存放各种文件的宏定义)
#pragma once //管理员文件 #define ADMIN_FILE "admin.txt" //学生文件 #define STUDENT_FILE "student.txt" //教师文件 #define TEACHER_FILE "teacher.txt" //机房文件 #define COMPUTER_FILE "computerRoom.txt" //订单文件 #define ORDER_FILE "order.txt"computerRoom.h(机房类)个人感觉可以升级一下,插入新的机房什么的
#pragma once #include<iostream> using namespace std; class computerRoom { public: int m_ComId;//机房的编号 int m_MaxNum;//机房大小 };orderFile.h(容器类)
#pragma once #include<iostream> using namespace std; #include"globalFile.h" #include<fstream> #include<map> #include<string> class OrderFile { public: //默认构造函数 OrderFile(); //更新预约记录 void updataOrder(); //记录预约信息数量 int m_Size; //记录所有信息的容器 key是记录的条数 value记录的是信息 map<int, map<string, string>> m_orderData; };源文件:(.cpp)
机房预约系统.cpp(主程序)
#include<iostream> using namespace std; #include"Identity.h" #include<fstream> #include<string> #include"globalFile.h" #include"student.h" #include"teacher.h" #include"manager.h" void teacherMenu(Identity * &teacher)//教师菜单 { while (true) { teacher->operMenu(); Teacher * tea = (Teacher*)teacher; int select; cin >> select; if (select == 1)//查看所有预约 { //cout << "查看所有预约" << endl; tea->showAllOrder(); } else if (select == 2)//审核预约 { //cout << "审核预约" << endl; tea->vaildOrder(); } else if (select == 0) { delete teacher; cout << "注销成功!!" << endl; system("pause"); system("cls"); return; } else { cout << "输入有误,请重新输入!!" << endl; system("pause"); system("cls"); } } } void studentMenu(Identity * &student)//学生菜单 { while (true) { student->operMenu(); Student * stu = (Student*)student; int select; cin >> select; if (select == 1)//申请预约 { //cout << "申请预约" << endl; stu->applyOrder(); } else if (select == 2)//查看自身预约 { //cout << "查看自身预约" << endl; stu->showMyOrder(); } else if (select == 3)//查看所有人预约 { //cout << "查看所有人预约" << endl; stu->showAllOrder(); } else if (select == 4)//取消预约 { //cout << "取消预约" << endl; stu->cancelOrder(); } else if(select==0) { delete student; cout << "注销成功!!" << endl; system("pause"); system("cls"); return; } else { cout << "输入有误,请重新输入!!" << endl; system("pause"); system("cls"); } } } void managerMenu(Identity * &manager)//管理员菜单 { while (true) { manager->operMenu(); Manager * man = (Manager*)manager; int select; cin >> select; if (select == 1)//添加账号 { //cout << "添加账号" << endl; man->addPerson(); } else if (select == 2)//查看账号 { //cout << "查看账号" << endl; man->showPerson(); } else if (select == 3)//查看机房 { //cout << "查看机房" << endl; man->showComputer(); } else if (select == 4)//清空预约 { //cout << "清空预约" << endl; man->cleanFile(); } else if(select==0) { delete manager; cout << "注销成功!!" << endl; system("pause"); system("cls"); return; } else { cout << "输入有误,请重新输入!!" << endl; system("pause"); system("cls"); } } } //登陆 文件名和类型传入 void LoginIn(string filename, int type) { Identity * p = NULL; ifstream ifs; ifs.open(filename, ios::in); if (!ifs.is_open()) { cout << "文件不存在" << endl; ifs.close(); return; } int id=0; string name; string pwd; if (type == 1)//学生身份 { cout << "请输入你的学号" << endl; cin >> id; } else if (type == 2) { cout << "请输入你的职工号" << endl; cin >> id; } cout << "请输入你的名字" << endl; cin >> name; cout << "请输入你的密码" << endl; cin >> pwd; if (type == 1) { //学生登陆 int fId; string fName; string fPwd; while (ifs >> fId && ifs >> fName && ifs >> fPwd) { if (fId == id && fName == name && fPwd == pwd) { cout << "学生验证登陆成功!" << endl; system("pause"); system("cls"); p = new Student(id, name, pwd); studentMenu(p); return; } } } else if (type == 2) { //教师登陆 int fId; string fName; string fPwd; while (ifs >> fId && ifs >> fName && ifs >> fPwd) { if (fId == id && fName == name && fPwd == pwd) { cout << "教师验证登陆成功!" << endl; system("pause"); system("cls"); p = new Teacher(id, name, pwd); teacherMenu(p); return; } } } else if (type == 3) { //管理员登陆 string fName; string fPwd; while (ifs >> fName && ifs >> fPwd) { if (fName == name && fPwd == pwd) { cout << "验证登陆成功!" << endl; system("pause"); system("cls"); p = new Manager(name, pwd); managerMenu(p); return; } } } cout << "验证登陆失败!" << endl; system("pause"); system("cls"); return; } int main() { int select; while (true) { cout << "=======================机房预约系统=======================" << endl; cout << "\t--------------------------------------" << endl; cout << "\t| 1.学生登陆 |" << endl; cout << "\t| |" << endl; cout << "\t| 2.教师登陆 |" << endl; cout << "\t| |" << endl; cout << "\t| 3.管理员登陆 |" << endl; cout << "\t| |" << endl; cout << "\t| 0.退出登陆 |" << endl; cout << "\t--------------------------------------" << endl; cout << "请输入您的选择:" << endl; cin >> select; switch (select) { case 1://学生登陆 LoginIn(STUDENT_FILE, 1); break; case 2://教师登陆 LoginIn(TEACHER_FILE, 2); break; case 3://管理员登陆 LoginIn(ADMIN_FILE, 3); break; case 0://退出登陆 cout << "欢迎下一次使用!!" << endl; system("pause"); return 0; break; default: cout << "输入有误,请重新输入!!" << endl; system("pause"); system("cls"); break; } } system("pause"); return 0; }manager.cpp(管理员子函数实现)
#include"manager.h" //默认构造函数 Manager::Manager() { } //有参构造函数 Manager::Manager(string name, string pwd) { m_Name = name; m_Pwd = pwd; this->initVector(); //初始化机房信息 ifstream ifs; ifs.open(COMPUTER_FILE, ios::in); computerRoom com; while (ifs >> com.m_ComId&&ifs >> com.m_MaxNum) { vcom.push_back(com); } ifs.close(); //cout << "机房的数量为 : " << vcom.size() << endl; } //菜单界面 void Manager::operMenu() { cout << "欢迎管理员:" << m_Name << "登陆!" << endl; cout << "\t--------------------------------------" << endl; cout << "\t| 1.添加账号 |" << endl; cout << "\t| |" << endl; cout << "\t| 2.查看账号 |" << endl; cout << "\t| |" << endl; cout << "\t| 3.查看机房 |" << endl; cout << "\t| |" << endl; cout << "\t| 4.清空预约 |" << endl; cout << "\t| |" << endl; cout << "\t| 0.退出登陆 |" << endl; cout << "\t--------------------------------------" << endl; cout << "请输入您的选择:" << endl; } //添加账号 void Manager::addPerson() { string filename; string tip; ofstream ofs; int select; string errorTip; while (true) { cout << "请输入添加账号的类型" << endl; cout << "1.学生" << endl; cout << "2.教师" << endl; cin >> select; if (select == 1) { filename = STUDENT_FILE; tip= "请输入学号" ; errorTip = "学生信息重复,请重新输入"; break; } else if (select == 2) { filename = TEACHER_FILE; tip= "请输入教师编号" ; errorTip = "教师信息重复,请重新输入"; break; } else { cout<< "输入错误,请重新输入" <<endl; system("pause"); //system("cls"); } } ofs.open(filename, ios::out | ios::app); int id; string name; string pwd; cout << tip <<endl; while (true) { cin >> id; bool ret = checkRepect(id, select); if (ret) { cout << errorTip << endl; } else { break; } } cout << "请输入姓名:" << endl; cin >> name; cout << "请输入密码" << endl; cin >> pwd; ofs << id << " " << name << " " << pwd <<" "<< endl; cout << "添加成功!" << endl; system("pause"); system("cls"); ofs.close(); this->initVector(); } void printfStudent(Student& s) { cout << "学号 " << s.m_Id << "姓名 " << s.m_Name << "密码 " << s.m_Pwd << endl; } void printfTeacher(Teacher& t) { cout << "教师编号 " << t.EmpId << "姓名 " << t.m_Name << "密码 " << t.m_Pwd << endl; } //查看账号 void Manager::showPerson() { int select; while (true) { cout << "请选择要查看的内容:" << endl; cout << "1.查看所有学生信息" << endl; cout << "2.查找所有老师信息" << endl; cin >> select; if (select == 1) { cout << "所有学生信息如下:" << endl; for_each(vstu.begin(), vstu.end(), printfStudent); break; } else if (select == 2) { cout << "所有教师信息如下:" << endl; for_each(vtea.begin(), vtea.end(), printfTeacher); break; } else { cout << "输入有误,请重新输入!!"; } } system("pause"); system("cls"); } //查看所有机房 void Manager::showComputer() { cout << "所有机房信息如下:" << endl; for (vector<computerRoom>::iterator com = vcom.begin(); com != vcom.end(); com++) { cout << "机房编号: " << (*com).m_ComId << " 机房大小为: " << (*com).m_MaxNum << endl; } system("pause"); system("cls"); } //清空预约记录 void Manager::cleanFile() { cout << "是否要清空预约记录?" << endl; cout << "1.是"<<endl; cout << "2.否" << endl; int select; cin >> select; while (true) { if (select == 1) { ofstream ofs; ofs.open(ORDER_FILE, ios::trunc);//trunc会在打开的时候清空文件 ofs.close(); cout << "清空成功" << endl; system("pause"); system("cls"); break; } else if (select == 2) { system("pause"); system("cls"); return; } else { cout << "输入有误,请重新输入" << endl; } } } void Manager::initVector() { //读取学生文件中的信息 ifstream ifs; ifs.open(STUDENT_FILE, ios::in); if (!ifs.is_open()) { cout << "文件打开失败" << endl; return; } vstu.clear(); vtea.clear(); Student s; while (ifs >> s.m_Id&&ifs >> s.m_Name&&ifs >> s.m_Pwd) { vstu.push_back(s); } //cout << "学生的数量为: " << vstu.size() << endl; ifs.close(); //读取老师的信息 ifs.open(TEACHER_FILE, ios::in); if (!ifs.is_open()) { cout << "文件打开失败" << endl; return; } Teacher t; while (ifs >> t.EmpId&&ifs >> t.m_Name&&ifs >> t.m_Pwd) { vtea.push_back(t); } //cout << "教师的数量为: " << vtea.size() << endl; ifs.close(); } bool Manager::checkRepect(int id, int type) { if (type == 1) { for (vector<Student>::iterator it = vstu.begin(); it != vstu.end(); it++) { if ((*it).m_Id == id) return true; } } else if(type==2) { for (vector<Teacher>::iterator its = vtea.begin(); its != vtea.end(); its++) { if ((*its).EmpId == id) return true; } } return false; }teacher.cpp(教师)
#include"teacher.h" //默认构造函数 Teacher::Teacher() { } //有参构造函数 Teacher::Teacher(int empid, string name, string pwd) { this->EmpId = empid; m_Name = name; m_Pwd = pwd; } //子菜单 void Teacher::operMenu() { cout << "欢迎教师:" << m_Name << "登陆!" << endl; cout << "\t--------------------------------------" << endl; cout << "\t| |" << endl; cout << "\t| 1.查看所有预约 |" << endl; cout << "\t| |" << endl; cout << "\t| |" << endl; cout << "\t| 2.审核预约 |" << endl; cout << "\t| |" << endl; cout << "\t| |" << endl; cout << "\t| 0.退出登陆 |" << endl; cout << "\t| |" << endl; cout << "\t--------------------------------------" << endl; cout << "请输入您的选择:" << endl; } //查看所有预约 void Teacher::showAllOrder() { OrderFile of; if (of.m_Size == 0) { cout << "无预约记录!!" << endl; system("pause"); system("cls"); return; } for (int i = 0; i < of.m_Size; i++) { cout << i + 1 << "."; cout << "预约时间: 周" << of.m_orderData[i]["data"]; cout << " 时间段: " << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); cout << " 学号: " << of.m_orderData[i]["stuId"]; cout << " 姓名: " << of.m_orderData[i]["stuName"]; cout << " 机房号: " << of.m_orderData[i]["roomId"]; string status = " 状态: ";//1。审核中 2.已预约 -1.预约失败 0.取消预约 if (of.m_orderData[i]["status"] == "1") { status += "审核中"; } else if (of.m_orderData[i]["status"] == "2") { status += "预约成功"; } else if (of.m_orderData[i]["status"] == "-1") { status += "预约失败"; } else { status += "预约已取消"; } cout << status << endl; } system("pause"); system("cls"); } //审核预约 void Teacher::vaildOrder() { OrderFile of; if (of.m_Size == 0) { cout << "无预约记录!!" << endl; system("pause"); system("cls"); return; } cout << "待审核的预约记录如下:" << endl; vector<int>v; int index = 1; for (int i = 0; i < of.m_Size; i++) { if (of.m_orderData[i]["status"] == "1") { v.push_back(i); cout << index++ << "."; cout << "预约时间: 周" << of.m_orderData[i]["data"]; cout << " 时间段: " << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); cout << " 机房号: " << of.m_orderData[i]["roomId"]; string status = " 状态: 审核中"; cout << status << endl; } } cout << "请输入审核的预约记录,按0返回" << endl; int select = 0; int ret = 0;//审核结果 while (true) { cin >> select; if (select >= 0 && select <= v.size()) { if (select == 0) { break; } else { cout << "请输入审核的结果" << endl; cout << "1.通过" << endl; cout << "2.不通过" << endl; while (true) { cin >> ret; if (ret == 1) { of.m_orderData[v[select - 1]]["status"] = "2"; of.updataOrder(); cout << "审核完毕" << endl; break; } else if (ret == 2) { of.m_orderData[v[select - 1]]["status"] = "-1"; of.updataOrder(); cout << "审核完毕" << endl; break; } else { cout << "输入有误,请重新输入" << endl; system("pause"); } } break; } } cout << "输入有误,请重新输入!" << endl; } system("pause"); system("cls"); }student.cpp(学生)
#include"student.h" //默认构造函数 Student::Student() { } //有参构造函数 Student::Student(int id, string name, string pwd) { m_Id = id; m_Name = name; m_Pwd = pwd; //初始化机房信息 ifstream ifs; ifs.open(COMPUTER_FILE, ios::in); computerRoom com; while (ifs >> com.m_ComId&&ifs >> com.m_MaxNum) { vcom.push_back(com); } ifs.close(); } //菜单界面 void Student::operMenu() { cout << "欢迎学生: " << m_Name << " 登陆!" << endl; cout << "\t--------------------------------------" << endl; cout << "\t| 1.申请预约 |" << endl; cout << "\t| |" << endl; cout << "\t| 2.查看自身预约 |" << endl; cout << "\t| |" << endl; cout << "\t| 3.查看所有人预约 |" << endl; cout << "\t| |" << endl; cout << "\t| 4.取消预约 |" << endl; cout << "\t| |" << endl; cout << "\t| 0.退出登陆 |" << endl; cout << "\t--------------------------------------" << endl; cout << "请输入您的选择:" << endl; } //申请预约 void Student::applyOrder() { cout << "机房开放时间为周一到周五!" << endl; cout << "请输入申请预约的时间:" << endl; cout << "1.周一" << endl; cout << "2.周二" << endl; cout << "3.周三" << endl; cout << "4.周四" << endl; cout << "5.周五" << endl; int data = 0;//日期 int interval = 0;//时间段 int room = 0;//机房编号 while (true) { cin >> data; if (data >= 1 && data <= 5) { break; } else { cout << "输入有误!!请重新输入" << endl; } } cout << "请输入申请预约的时间段:" << endl; cout << "1.上午" << endl; cout << "2.下午" << endl; while (true) { cin >> interval; if (interval >= 1 && interval <= 2) { break; } cout<< "输入有误!!请重新输入" << endl; } cout << "请选择机房:" << endl; for (int i = 0; i < vcom.size(); i++) { cout << vcom[i].m_ComId << "号机房的容量为: " << vcom[i].m_MaxNum << endl; } while (true) { cin >> room; if (interval >= 1 && interval <= 3) { break; } cout << "输入有误!!请重新输入" << endl; } cout << "预约成功!审核中" << endl; ofstream ofs; ofs.open(ORDER_FILE, ios::app); ofs << "data:" << data << " "; ofs << "interval:" << interval << " "; ofs << "stuId:" << m_Id << " "; ofs<< "stuName:" << m_Name << " "; ofs << "roomId:" << room<<" "; ofs << "status:" << 1 << endl; ofs.close(); system("pause"); system("cls"); } //查看预约 void Student::showMyOrder() { OrderFile of; if (of.m_Size == 0) { cout << "无预约记录!!" << endl; system("pause"); system("cls"); return; } for (int i = 0; i < of.m_Size; i++) { if (m_Id == atoi(of.m_orderData[i]["stuId"].c_str()))//找到自己的信息 { cout << "预约时间: 周" << of.m_orderData[i]["data"]; cout << " 时间段: " << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); cout << " 机房号: " << of.m_orderData[i]["roomId"]; string status = " 状态: ";//1。审核中 2.已预约 -1.预约失败 0.取消预约 if (of.m_orderData[i]["status"] == "1") { status += "审核中"; } else if (of.m_orderData[i]["status"] == "2") { status += "预约成功"; } else if (of.m_orderData[i]["status"] == "-1") { status += "预约失败"; } else { status += "预约已取消"; } cout << status<<endl; } } system("pause"); system("cls"); } //查看所有人预约 void Student::showAllOrder() { OrderFile of; if (of.m_Size == 0) { cout << "无预约记录!!" << endl; system("pause"); system("cls"); return; } for (int i = 0; i < of.m_Size; i++) { cout << i + 1 << "."; cout << "预约时间: 周" << of.m_orderData[i]["data"]; cout << " 时间段: " << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); cout << " 学号: " << of.m_orderData[i]["stuId"]; cout << " 姓名: " << of.m_orderData[i]["stuName"]; cout << " 机房号: " << of.m_orderData[i]["roomId"]; string status = " 状态: ";//1。审核中 2.已预约 -1.预约失败 0.取消预约 if (of.m_orderData[i]["status"] == "1") { status += "审核中"; } else if (of.m_orderData[i]["status"] == "2") { status += "预约成功"; } else if (of.m_orderData[i]["status"] == "-1") { status += "预约失败"; } else { status += "预约已取消"; } cout << status << endl; } system("pause"); system("cls"); } //取消预约 void Student::cancelOrder() { OrderFile of; if (of.m_Size == 0) { cout << "无预约记录!!" << endl; system("pause"); system("cls"); return; } cout << "审核中的或者预约成功的记录可以取消,请输入取消的记录:" << endl; vector<int>v; int index = 1; for (int i = 0; i < of.m_Size; i++) { if (m_Id == atoi(of.m_orderData[i]["stuId"].c_str()))//找到自己的信息 { if (of.m_orderData[i]["status"] == "2" || of.m_orderData[i]["status"] == "1") { v.push_back(i); cout << index++ << "."; cout << "预约时间: 周" << of.m_orderData[i]["data"]; cout << " 时间段: " << (of.m_orderData[i]["interval"] == "1" ? "上午" : "下午"); cout << " 机房号: " << of.m_orderData[i]["roomId"]; string status = " 状态: ";//1。审核中 2.已预约 -1.预约失败 0.取消预约 if (of.m_orderData[i]["status"] == "1") { status += "审核中"; } else if (of.m_orderData[i]["status"] == "2") { status += "预约成功"; } cout << status << endl; } } } cout << "请输入取消的记录,按0返回" << endl; int select = 0; while (true) { cin >> select; if (select >= 0 && select <= v.size()) { if (select == 0) { break; } else { of.m_orderData[v[select - 1]]["status"] = "0"; of.updataOrder(); cout << "已取消预约" << endl; break; } } cout << "输入有误,请重新输入!" << endl; } system("pause"); system("cls"); }orderFile.cpp(容器主要就是存储预约信息,然后可以提取里面的信息处理)
#include"orderFile.h" //默认构造函数 OrderFile::OrderFile() { ifstream ifs; ifs.open(ORDER_FILE, ios::in); string data;//日期 string interval;//时间段 string stuId;//学生id string stuName;//学生姓名 string roomId;//机房编号 string status;//预约状态 m_Size = 0;//记录条数 while (ifs >> data && ifs >> interval && ifs >> stuId && ifs >> stuName && ifs >> roomId && ifs >> status) { //cout << data << endl; //cout << interval << endl; //cout << stuId << endl; //cout << stuName << endl; //cout << roomId << endl; //cout << status << endl;//测试是否读取到数据 //data:1 string key; string value; map<string, string>m; int pos = data.find(":"); if (pos != -1) { key = data.substr(0, pos); value = data.substr(pos + 1, data.size() - pos - 1); m.insert(make_pair(key, value)); } pos = interval.find(":"); if (pos != -1) { key = interval.substr(0, pos); value = interval.substr(pos + 1, interval.size() - pos - 1); m.insert(make_pair(key, value)); } pos = stuId.find(":"); if (pos != -1) { key = stuId.substr(0, pos); value = stuId.substr(pos + 1, stuId.size() - pos - 1); m.insert(make_pair(key, value)); } pos = stuName.find(":"); if (pos != -1) { key = stuName.substr(0, pos); value = stuName.substr(pos + 1, stuName.size() - pos - 1); m.insert(make_pair(key, value)); } pos = roomId.find(":"); if (pos != -1) { key = roomId.substr(0, pos); value = roomId.substr(pos + 1, roomId.size() - pos - 1); m.insert(make_pair(key, value)); } pos = status.find(":"); if (pos != -1) { key = status.substr(0, pos); value = status.substr(pos + 1, status.size() - pos - 1); m.insert(make_pair(key, value)); } m_orderData.insert(make_pair(m_Size, m)); m_Size++; } ifs.close(); } //更新预约记录 void OrderFile::updataOrder() { if (m_Size == 0) { return; } ofstream ofs; ofs.open(ORDER_FILE, ios::out | ios::trunc); for (int i = 0; i < m_Size; i++) { ofs << "data:" << m_orderData[i]["data"] << " "; ofs << "interval:" << m_orderData[i]["interval"] << " "; ofs << "stuId:" << m_orderData[i]["stuId"] << " "; ofs << "stuName:" << m_orderData[i]["stuName"] << " "; ofs << "roomId:" << m_orderData[i]["roomId"] << " "; ofs << "status:" << m_orderData[i]["status"] << endl; } ofs.close(); }这个程序是在visual studio 2017下写的。