1. 程式人生 > >c++primer 練習11.7

c++primer 練習11.7

int main(int argc,char **argv) {
	
	map<string, vector<string>> imap;
	//ifstream in("ss.txt");
	string fname, gname;
	cout << "input your family name:\n";
	while (cin >> fname) {
		cout << "input your given name:\n";
		cin >> gname;
		imap[fname].push_back(gname);
		cout << "input your family name:\n";
	}
	for (auto f : imap) {
		cout << f.first << "家有" << f.second.size() << "小孩。\n他們的名字是:\n";
		ostream_iterator<string> out_iter(cout, " ");
		copy(f.second.cbegin(), f.second.cend(), out_iter);
		cout << endl;
	}
}