扩展练习11.7, 保存孩子的姓名和生日实现思路:map>>添加孩子信息时,用列表初始化创建名字和生日的pair,添`加到vector即可
```
#include#include#include#include#includeusing namespace std;void add_family(map>>& families, const string& family) { if (families.find(family) == families.end()) { families[family] = vector>(); }}void add_child(map>>& families, const string& family, const string& childName, const string& birthday) { families[family].push_back({childName, birthday});}int main() { map>> families;
add_family(families, "张");
add_child(families, "张", "强", "1970-1-1");
add_child(families, "张", "刚", "1980-1-1");
add_child(families, "王", "五", "1990-1-1");
add_family(families, "王");
for (auto f : families) {
cout << f.first << "家的孩子:";
for (auto c : f.second) {
cout << "姓名:" << c.first << "\n"
<< "生日:" << c.second << "\n";
}
cout << endl;
}
return 0;
}
```