Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;带多个按钮的后推式 我有以下C++代码…< /P> struct myType { int SID; int IID; std::string myString; }; std::vector<myType[2]> _type; struct myType { int-SID; 国际IID; std::string myString; }; std::矢量型;_C++_Vector_Types_Push Back - Fatal编程技术网

c++;带多个按钮的后推式 我有以下C++代码…< /P> struct myType { int SID; int IID; std::string myString; }; std::vector<myType[2]> _type; struct myType { int-SID; 国际IID; std::string myString; }; std::矢量型;

c++;带多个按钮的后推式 我有以下C++代码…< /P> struct myType { int SID; int IID; std::string myString; }; std::vector<myType[2]> _type; struct myType { int-SID; 国际IID; std::string myString; }; std::矢量型;,c++,vector,types,push-back,C++,Vector,Types,Push Back,问题是当我这样做的时候 for (int x = 1; x < 82432; x++) { _type.push_back(myType()); } for(int x=1;x

问题是当我这样做的时候

for (int x = 1; x < 82432; x++)
{
    _type.push_back(myType());
}
for(int x=1;x<82432;x++)
{
_type.push_back(myType());
}
它给了我以下的错误

Error   441 error C2664: 'void std::vector<myType [2],std::allocator<_Ty>>::push_back(const myType (&)[2])' : cannot convert argument 1 from 'myType' to 'myType (&&)[2]'
Error 441 Error C2664:'void std::vector::push_back(const myType(&)[2]):无法将参数1从'myType'转换为'myType(&&&)[2]'

其思想是创建一个向量数组,如下所示:_type[82431][2].SID您无法创建数组类型的向量,原因之一是您无法将一个数组分配给另一个数组,您可以得到的结果是:

std::vector<std::array<myType, 2>> _type;
std::vector\u类型;
这也是不对的

for (int x = 1; x < 82432; x++)
{
    _type.push_back(myType());
}
for(int x=1;x<82432;x++)
{
_type.push_back(myType());
}
即使您可以创建数组的向量,在循环中也会推送类型为
myType
的数据,而向量类型为
myType[2]
。因此,要使其与
std::array
一起工作,请更改为
\u类型。向后推({myType(),myType()})


请看这里了解一些其他用途,因为一些愚蠢的原因。。。我能做到

myType _type[82432][2];

有了这个,我仍然无法创建二维数组。。。我想要的是插入另一个具有相同类型的2。数组不是偶数。如果我早知道这一点,我就不会使用向量。。。哈哈,因为我只需要一个简单的数组访问。。。我想知道是否有一种方法可以用STD::vector?C++中,最好使用<代码> STD::vector < /COD>或<代码> STD::如果数组的两个维度是常数,你可以使用
std::array
,或者像Marcin的回答中那样的数组向量。我知道最好使用向量,但我得到的只是一个秃头。。。如果你有办法让vector看起来像上面的答案,请发布它!事实上,谢谢你!认为它可以像那样工作…上面的答案有什么问题吗?它提供了一种声明和填充向量的方法,以便为
myType\u type[82432][2]获得等价物