如何将多个值推回到向量中? [英] How to push_back multiple values into a vector?
问题描述
我知道以前有人问过这个问题,我知道在 C++11 中你可以做到
I know this question has been asked before, and I know that in C++11 you can do
vector<int> v = {2,5,8,11,14};
vector<int> v{2,5,8,11,14};
和
v.push_back({x,y});
但它给了我一个编译错误.我使用的是 Visual Studio Express 2012.
But it gives me a compile error. I'm using Visual Studio Express 2012.
我该如何实现?
附上错误截图:
推荐答案
Visual Studio 2012 不支持通过初始化列表进行向量初始化.VS2012 附带的标准库中缺少很多 C++11 支持,而 VS2012 C++ 编译器本身支持这些标准库.
Visual Studio 2012 does not support vector initialization via initializer lists. There is a lot of C++11 support missing from the standard library included with VS2012 that is supported by the VS2012 C++ compiler itself.
遗憾的是,与 VS2012 和 gcc 4.7 的情况一样,对新 C++11 功能的出色编译器支持受到部分库支持的阻碍,而部分库支持似乎总是落后于编译器.
Sadly, as is the case for VS2012 and was the case for gcc 4.7, awesome compiler support for the new C++11 features is hampered by partial library support which seems to always lag behind the compiler.
这篇关于如何将多个值推回到向量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!