初始化列表不使用矢量在Visual Studio 2012中? [英] Initializer list not working with vector in Visual Studio 2012?

查看:334
本文介绍了初始化列表不使用矢量在Visual Studio 2012中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Visual Studio 2012中的C ++ 11功能


所以我今天通过维基百科阅读了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};

当我在Visual Studio 2012中尝试以下操作时,我得到编译错误 C2552 :'vecs':非聚合不能用初始化器列表初始化



这是我的代码:

  #include< vector> 

using namespace std;

int main(){
vector< string> vecs = {h,g,e}; VS2012不支持初始化列表,或者我只是误解了一些东西吗?

>

谢谢!

解决方案

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

好吧,直到2012年11月CTP才开始。现在它,至少在alpha状态。授予,此代码仍然无法在其中工作,因为他们仍然把初始化列表放入标准库本身。


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

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

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

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?

Thanks!

解决方案

Visual Studio 2012 does not support initializer lists.

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.

这篇关于初始化列表不使用矢量在Visual Studio 2012中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆