C++圖書管理系統(tǒng)
2023-07-08 23:14 作者:GXgwenkiss | 我要投稿

up為什么編譯器會顯示這個錯誤啊實在弄不懂 + this 0x008ff8f0 {m_Index=0 m_Error=-858993460 m_BorrowerV=[0]() ...} SystemManage * const void SystemManage::borrowBooks() { //用戶輸入信息 string name; cout<<"請輸入您的姓名:"<<endl; cin>>name; string phone; cout<<"請輸入您的手機號碼"<<endl; cin>>phone; string id; cout<<"請輸入您的賬號"<<endl; cin>>id; string mima; cout<<"請輸入您的密碼:"<<endl; cin>>mima; ifstream ifs2; ifs2.open("用戶注冊信息.txt",ios::in); vector<string>tempV1;//解析 用戶注冊信息.txt string borrowerData;//用戶注冊信息 while(ifs2>>borrowerData)//解析 用戶注冊信息.txt { int pos=-1; int start=0; while(1) { pos=borrowerData.find(",",start); if(pos == -1) { break; } string target=borrowerData.substr(start,pos-start); tempV1.push_back(target); start=pos+1; } } ifs2.close(); system("pause"); //將用戶輸入的信息 跟解析到容器的信息進行對比 return int num=0; for(vector<string>::iterator it=tempV1.begin();it!=tempV1.end();it++) { if(id==*it)//先檢查賬號是否正確輸入 { num++;//檢測賬號是否注冊 是否與系統(tǒng)內的數(shù)據(jù)庫匹配 it++; if(*it==mima)//再檢查密碼是否正確輸入 { cout<<"登陸成功!"<<endl; break; } else { cout<<"賬號或密碼輸入錯誤!"<<endl; cout<<"請重新操作,謝謝!"<<endl; system("pause"); system("cls"); this->m_Error=-1;//借書狀態(tài)異常 return;//返回到主菜單 租借圖書 功能 } } } //遍歷完沒有匹配到賬號 if(num == 0) { cout<<"該賬號尚未注冊!"<<endl; cout<<"請重新操作,謝謝!"<<endl; system("pause"); system("cls"); this->m_Error=-1;//借書狀態(tài)異常 return;//返回主菜單 } //開始借書 system("cls"); cout<<"**********************************"<<endl; cout<<"歡迎使用圖書管理系統(tǒng) 所有系統(tǒng)內的圖書如下:"<<endl; cout<<"**********************************"<<endl; //展示系統(tǒng)的所有圖書 this->showOnBorrow(); //輸入一本想借的圖書 cout<<"請輸入想要租借的書名:"<<endl; string bookName2; cin>>bookName2; //打開系統(tǒng)圖書文件 vector<string>v3; ifstream ifs5; ifs5.open("系統(tǒng)圖書.txt",ios::in); string bookData3; while(ifs5>>bookData3) { //解析數(shù)據(jù)到容器中 int start3= 0 ; int pos3= -1 ; while(1) { pos3=bookData3.find (",",start3); if(pos3 == -1) { break; } string target =bookData3.substr(start3,pos3-start3); v3.push_back(target); start3=pos3+1; } } ifs5.close(); //如果沒有匹配到 return int count2=0; for(vector<string>::iterator it=v3.begin();it!=v3.end();it++) { count2++; if(bookName2 == *it) {break;} if(count2 == v3.size()) { cout<<"系統(tǒng)內沒有該圖書!"<<endl; system("pause"); system("cls"); this->m_Error=-1; return; } } //對比 遍歷匹配 vector<string>temp_v;//臨時容器 借走的圖書 for(vector<string>::iterator it=v3.begin();it!=v3.end();it++) { if(*it==bookName2) { //把租借的圖書放到一個容器中 it--; temp_v.assign(it,it+3);//臨時容器 v3.erase(it,it+3); break; } } this->m_shengXiaV = v3;//儲存剩下的部分 for(int i=0;i<4;i++) { if(i==0) { this->m_BorrowerV.push_back(name); } if(i==1) { this->m_BorrowerV.push_back(id); } if(i==2) { this->m_BorrowerV.push_back(phone); } if(i==3) { for(vector<string>::iterator it=temp_v.begin ();it!=temp_v.end();it++) { this->m_BorrowerV.push_back(*it); } } } //通過容器將數(shù)據(jù)導入 借書人信息.txt ofstream ofs2; ofs2.open("借書人信息.txt",ios::out|ios::app); for(int i=0;i<6;i++) { ofs2<<this->m_BorrowerV[i]<<","; } ofs2.close(); m_BorrowerV.clear(); //2.刪除后剩下的圖書放回到系統(tǒng)圖書.txt //清空掉原來的系統(tǒng)圖書 ofstream ofs; ofs.open("系統(tǒng)圖書.txt",ios::trunc); ofs.close(); cout<<"成功租借"<<bookName2<<endl; system("pause"); system("cls"); //借書人信息組成 6 姓名 賬號 手機號 一本圖書(3) }
標簽: