临时数组赋值 (C++)
int arr[2][6] = {{0,0,0,1,1,1},
{2,2,2,3,3,3}};
for(int row=0;row<2;row++)
{
for(int col=0;col<6;col++)
{
int temp[] = arr[row][col+4],arr[row][col+5],arr[row+1][col],arr[row+1][col+1];
for(int i=0;i<1;i++)
{
cout << temp[i] << endl;
//Replace 4 values in arr[] with values from temp[]
}
}
}
我正在尝试创建一个较小的临时数组,以便在更新原始二维数组时从中提取值。我收到以 int temp[]
开头的行错误。错误如下:
聚合对象预计使用“{...}”进行初始化
我不确定这里出了什么问题,我是 C++ 的初学者。
int arr[2][6] = {{0,0,0,1,1,1},
{2,2,2,3,3,3}};
for(int row=0;row<2;row++)
{
for(int col=0;col<6;col++)
{
int temp[] = arr[row][col+4],arr[row][col+5],arr[row+1][col],arr[row+1][col+1];
for(int i=0;i<1;i++)
{
cout << temp[i] << endl;
//Replace 4 values in arr[] with values from temp[]
}
}
}
I'm trying to create a smaller temporary array to pull values from when updating the original 2D array. I'm getting an error with the line starting with int temp[]
. The error reads:
initialization with '{...}' expected for aggregate object
I'm not sure what's going wrong here, I am a beginner with C++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试使用单个
int
初始化一个int[]
数组。您在数组的初始化值周围缺少大括号(请参阅其他数组上的大括号),例如:You are trying to initialize an
int[]
array with singleint
. You are missing curly braces around the array's initialization values (see the braces on your other array), eg: