C++ 初始值设定项列表不适用于 Visual Studio 2012 中的向量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12654394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:29:02  来源:igfitidea点击:

Initializer list not working with vector in Visual Studio 2012?

c++visual-c++c++11visual-studio-2012

提问by Polaris878

Possible Duplicate:
C++11 features in Visual Studio 2012

可能的重复:
Visual Studio 2012 中的 C++11 功能

So I was reading up on C++11 initializer lists today via Wikipediaand saw that C++11 supports the following syntax for the standard containers:

所以我今天通过维基百科阅读了 C++11 初始化列表,看到 C++11 支持标准容器的以下语法:

std::vector<std::string> v = { "xyzzy", "plugh", "abracadabra" };
std::vector<std::string> v({ "xyzzy", "plugh", "abracadabra" });
std::vector<std::string> v{ "xyzzy", "plugh", "abracadabra" }; 

When I try the following in Visual Studio 2012 I get the compilation error C2552: 'vecs' : non-aggregates cannot be initialized with initializer list

当我在 Visual Studio 2012 中尝试以下操作时,出现编译错误 C2552: 'vecs' : non-aggregates cannot be initialized with initializer list

Here is my code:

这是我的代码:

#include <vector>

using namespace std;

int main() {
    vector<string> vecs = {"h", "g", "e"};
}

Does VS2012 not support initializer lists or am I just misunderstanding something?

VS2012 不支持初始化列表还是我误解了什么?

Thanks!

谢谢!

回答by Nicol Bolas

Visual Studio 2012 does not support initializer lists.

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

Well, it didn't until the November 2012 CTP. Now it does, at least in an alpha state. Granted, this code still won't work in it because they're still putting initializer lists into the standard library itself.

嗯,直到 2012 年 11 月 CTP 才出现。现在确实如此,至少处于 alpha 状态。当然,这段代码仍然无法在其中工作,因为他们仍在将初始化列表放入标准库本身。