0
#include <iostream>
#include <string>
#include <unordered_set>

template<class T>
T cmerge (T a, T b) { T t(a); t.insert(b.begin(),b.end()); return t; }

int main ()
{
    std::unordered_set<std::string> first;                                // empty
    std::unordered_set<std::string> second ( {"red","green","blue"} );    // init list
    std::unordered_set<std::string> third ( {"orange","pink","yellow"} ); // init list
    std::unordered_set<std::string> fourth ( second );                    // copy
    std::unordered_set<std::string> fifth ( cmerge(third,fourth) );       // move
    std::unordered_set<std::string> sixth ( fifth.begin(), fifth.end() ); // range

    std::cout << "sixth contains:";
    for (const std::string& x: sixth) std::cout << " " << x;
    std::cout << std::endl;

    return 0;
}

这段代码(复制自http://www.cplusplus.com/reference/unordered_set/unordered_set/unordered_set/)无法在visual studio 2012下正确编译。我想知道visual studio是否支持可以列出unordered_set(或stl的其他容器)?请告诉我答案,谢谢!

4

1 回答 1

0

VC11 (Visual Studio 2012) 不支持初始化列表。

http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx

为此,您需要 Visual Studio 2013,它实现了此功能以及许多其他 C+11 功能。

于 2013-10-26T19:01:28.387 回答