我必须使用具有 10 个名称的集合容器。它输出“Myset contains”但没有列出名称,我不知道为什么。
#include "stdafx.h"
#include <iostream>
#include <string>
#include <set>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
std::string names[] = {"Nathan", "Dereck", "Robert", "Michael", "Elliot"
"Oliva", "Sophia", "Jessica", "Alexis", "Erin"};
//std::set <std::string> set(std::begin(names), std::end(names));
std::set<string> mynames (names, names);
std::cout << "Myset contains: ";
for (std::set<string>::iterator it=mynames.begin(); it!=mynames.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
int foo;
cin >> foo;
return 0;
}