#include <bits/stdc++.h> #include <windows.h> using namespace std; struct book{ string name; float money; string cbs; string writer; int kc; string type; int id; }; int main(){ while(1){ system("cls"); cout<<"****图书管理****"<<endl; cout<<"1.书名"<<endl<<"2.类型"<<endl<<"3.借书"<<endl<<"4.退出系统"<<endl; map<string,book> books; map<string,string> types; map<string,string> logs; int startid=1000; int number=0; book x[100]; book b; string data,name_,cbs_,writer_,type_; int money_,kc_; ifstream a; a.open("book.txt"); while(getline(a,data)){ if(data.length()>5){ int length=data.find("|"); name_=data.substr(0,length); data=data.substr(length+1); length=data.find("|"); cbs_=data.substr(0,length); data=data.substr(length+1); length=data.find("|"); money_=stoi(data.substr(0,length)); data=data.substr(length+1); length=data.find("|"); writer_=data.substr(0,length); data=data.substr(length+1); length=data.find("|"); kc_=stoi(data.substr(0,length)); data=data.substr(length+1); length=data.find("|"); type_=data.substr(0,length); x[number].name=name_; x[number].cbs=cbs_; x[number].money=money_; x[number].writer=writer_; x[number].kc=kc_; x[number].type=type_; number++; } if(a.eof()){ cout<<"end"<<endl; break; } } a.close(); // books.insert(pair<string,book>("骆驼祥子",b)); // books.insert(pair<string,book>("朝花夕拾",b)); // books.insert(pair<string,book>("昆虫记",b)); int n; cin>>n; string name,_type; if(n==4){ system("cls"); break; } switch(n){ case 1: system("cls"); cout<<"请输入书名"<<endl; cin>>name; for(int i=0;i<=number;i++){ if(name==x[i].name){ cout<<"信息如下"<<endl; cout<<"书名:"<<x[i].name<<endl; cout<<"出版社:"<<x[i].cbs<<endl; cout<<"价格:"<<x[i].money<<endl; cout<<"作者:"<<x[i].writer<<endl; cout<<"剩余本数:"<<x[i].kc<<endl; cout<<"类型:"<<x[i].type<<endl; cout<<"_________________________"<<endl; } } Sleep(5000); break; case 2: system("cls"); cout<<"请输入类型"<<endl; cin>>_type; cout<<"此类型书籍如下:"<<endl; for(int i=0;i<=number;i++){ if(x[i].type==_type){ cout<<x[i].name<<endl; } } Sleep(5000); break; case 3: system("cls"); cout<<"请输入你想借的书名"<<endl; cin>>name; for(int i=0;i<=number;i++){ if(x[i].kc==0){ cout<<"此书已经被借走"<<endl; } } Sleep(5000); break; } } return 0; }
标签:name,int,系统,number,substr,length,data,图书 From: https://www.cnblogs.com/fushuxuan/p/18078135