#include #include #include #include using namespace std;typedef map> HOMEMAP;//输出MAPvoid showHomeMap(const HOMEMAP& homeMap){ for(HOMEMAP::const_iterator i = homeMap.begin();i!= homeMap.end();++i){ string firstName = i->first; vector secondName = i->second; for(unsigned int j = 0;j!= secondName.size();++j){ cout< } }}//根据姓氏输出void showSecondNameByFirstName(string firstName, HOMEMAP& homeMap){ vector secondName = homeMap[firstName]; for(unsigned int j = 0;j!= secondName.size();++j){ cout< } if(secondName.size() == 0){ cout<<"未找到此姓氏"< }}int main(){ HOMEMAP homeMap; //初始化6组数据 一 二代表小孩的名字,可以自己去改 vector vecs; vecs.push_back("一"); vecs.push_back("二"); homeMap["李"] = vecs; vecs.clear(); vecs.push_back("一"); vecs.push_back("二"); homeMap["王"] = vecs; vecs.clear(); vecs.push_back("一"); vecs.push_back("二"); homeMap["张"] = vecs; vecs.clear(); vecs.push_back("一"); vecs.push_back("二"); homeMap["马"] = vecs; vecs.clear(); vecs.push_back("一"); vecs.push_back("二"); homeMap["宁"] = vecs; vecs.clear(); vecs.push_back("一"); vecs.push_back("二"); homeMap["杨"] = vecs;//使用方法: showHomeMap(homeMap); showSecondNameByFirstName("李",homeMap); system("pause"); return 0;}