#include
#include
#include
#include
#include
int main() {
map
string new_family;
string new_child_surname;
string new_child_name;
int x;
cout << " 输入1添加新的家庭,输入2添加已有家庭的孩子" << endl;
while (cin >> x&&x!=0) {
if (x == 1) {
cout << "输入新的家庭:";
cin >> new_family;
family_map.insert(pair
//利用pair 插入map 元素,也可以把pair改成:map
cout << "新的家庭已经添加:" << endl;
}if (x == 2) {
cout << "输入需要新加入的孩子的姓:";
cin >> new_child_surname;
cout << "输入需要新加入的孩子的名:";
cin >> new_child_name;
for (const auto& x : family_map) {
if (x.first == new_child_surname) {
family_map[x.first] .push_back(new_child_name);
}
}
}
}
for (const auto& x : family_map) {
cout << x.first << ":";
for (auto y : x.second)cout << y<
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)