0

我必须使用具有 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;
}
4

1 回答 1

0

改变:

std::set<string> mynames (names, names);

进入:

std::set<string> mynames (names, names+number_of_elements);
于 2013-09-25T17:21:38.923 回答