#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream input("inputfile.txt");
string author,bookname;
multimap<string,string> bookInfo;
//将文件中信息读入multimap
while (input>>author>>bookname) {
bookInfo.insert(make_pair(author, bookname));
}
input.clear();
input.close();
//显示信息
cout<<"****************************************"<<endl;
cout<<"The author and the book table "<<endl;
multimap<string,string>::const_iterator beginIter = bookInfo.begin();
multimap<string,string>::const_iterator endIter = bookInfo.end();
for ( ; beginIter != endIter; ++beginIter) {
cout<<"The name :"<<beginIter->first<<"\t\t"<<"The book :"<<beginIter->second<<endl;
}
cout<<"****************************************"<<endl;
//删除指定作者的相关信息
string findAuthor;
cout<<"Please input the delete author : ";
while (cin >> findAuthor) {
int delNum = 0;
multimap<string,string>::const_iterator mulIter = bookInfo.find(findAuthor);
if (mulIter != bookInfo.end()) {
delNum = bookInfo.erase(mulIter->first);
}
cout<<"The delete number is "<<delNum<<endl;
//打印删除后信息
cout<<"****************************************"<<endl;
cout<<"After delete,the author and the book table "<<endl;
multimap<string,string>::const_iterator beginIter = bookInfo.begin();
multimap<string,string>::const_iterator endIter = bookInfo.end();
for (; beginIter != endIter; ++beginIter) {
cout<<"The name :"<<beginIter->first<<"\t\t"<<"The book :"<<beginIter->second<<endl;
}
cout<<"****************************************"<<endl;
cout<<"Please input the delete author : ";
}
return 0;
}
保存信息的文件inputfile.txt
'em them
cuz because
gratz grateful
i I
nah no
pos supposed
sez said
tanx thanks
wuz was
nah no
pos supposed
sez said
tanx thanks
wuz was
nah no
pos supposed
sez said
tanx thanks
wuz was