visual studio 2012不支持列表初始化unordered_set(c ++ stl)?

时间:2013-10-26 14:48:15

标签: c++ visual-studio-2012 stl

#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容器)初始化的功能?请告诉我答案,谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

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