#include <bits/stdc++.h> using namespace std; struct book{ string name; float money; string cbs; string writer; int kc; string id; }; int main(){ while(1){ cout<<"****图书管理****"<<endl; cout<<"1.***书名***"<<endl; map<string,book> n_map; book b; string data; ifstream a; a.open("book.txt"); while(getline(a,data)){ if(data.length()>5){ int length=data.find("|"); b.name=data.substr(0,length); cout<<b.name<<endl; data=data.substr(length+1); length=data.find("|"); b.cbs=data.substr(0,length); cout<<b.cbs<<endl; data=data.substr(length+1); length=data.find("|"); b.money=stoi(data.substr(0,length)); cout<<b.money<<endl; data=data.substr(length+1); length=data.find("|"); b.writer=data.substr(0,length); cout<<b.writer<<endl; data=data.substr(length+1); length=data.find("|"); b.kc=stoi(data.substr(0,length)); cout<<b.kc<<endl; data=data.substr(length+1); length=data.find("|"); b.id=stoi(data.substr(0,length)); cout<<b.id<<endl; } if(a.eof()){ cout<<"end"<<endl; break; } } a.close(); n_map["yuwne"]=b; n_map["shuxue"]=b; n_map["yingyu"]=b; n_map.insert(pair<string,book>("yuwen",b)); int n; cin>>n; string name; switch(n){ case 1: cout<<"请输入书名(写拼音)"<<endl; cin>>name; } } return 0; }
标签:name,管理,int,cout,length,data,图书,string From: https://www.cnblogs.com/fushuxuan/p/18076760