#include <vector>
using namespace std;
vector<int[60]> v;
int s[60];
v.push_back(s);
此代码在 Visual Studio 2015 社区中报告编译错误:
错误(事件)没有重载函数实例“std::vector<_Ty, _Alloc>::push_back [with _Ty=int [60], _Alloc=std::allocator]”匹配参数列表
错误 C2664“void std::vector>::push_back(const int (&)[60])”:无法将参数 1 从“int”转换为“int (&&)[60]”
最佳答案
改为使用 std::array
:
#include <vector>
#include <array>
using namespace std;
int main()
{
vector<array<int, 10>> v;
array<int, 10> s;
v.push_back(s);
return 0;
}
但我也不得不质疑拥有一个包含数组的 vector 的目的。无论其背后的原因是什么,都可能有更好的方法来实现相同的目标。
关于C++ 如何将数组 int[10] push_back 到 std::vector<int[10]>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38215108/