- #include <iostream>
- #include <sstream>
- #include <string>
- #include <list>
- #include <fstream>
- #include <map>
- #include <vector>
- #include <utility>
- #include <iomanip> //控制格式输出的,
- using namespace std;
- std::ifstream &open_file(ifstream &in ,const string file_name)
- {
- in.close();
- in.clear();
- in.open(file_name.c_str());
- return in;
- }
- int main(int argc,char **argv)
- {
- map<string,vector<string>> family;
- while(true)
- {
- cout<<"请输入姓氏,输入q退出:";
- string xing;
- cin>>xing;
- if(xing=="q")
- break;
- cin.clear();
- string name;
- vector<string> vec;
- cout<<"输入家族成员名字:"<<endl;
- while(cin>>name)
- {
- vec.push_back(name);
- }
- family.insert(make_pair(xing,vec));
- cin.clear();
- }
- for(map<string,vector<string>>::iterator iter=family.begin();
- iter!=family.end();++iter)
- {
- cout<<"家族:"<<iter->first<<endl;
- for(vector<string>::const_iterator vit=(iter->second).begin();
- vit!=(iter->second).end();++vit)
- {
- cout<<setw(10)<<*vit<<endl;
- }
- }
- return 0;
- }
c++ primer 习题10.18
最新推荐文章于 2021-12-05 08:37:26 发布