简体   繁体   English

数组初始化程序中的多余元素

[英]Excess elements in array initializer

I'm currently trying to print a table, but I keep getting an error that I have too many elements in my array initializer. 我当前正在尝试打印表,但是我不断收到一个错误,表明我的数组初始化器中包含太多元素。 What did I do wrong? 我做错了什么? (Using Xcode) (使用Xcode)

int coordinates[5] [2] = {{x1,x2,x3,x4,x5},{y1,y2,y3,y4,y5}};
int coordinates[5] [2]

is an array of five arrays of two int elements each. 是一个由五个数组组成的数组 ,每个数组包含两个int元素。

Judging by your initialization, you want coordinates to be an array of two arrays of five int elements each: 通过初始化判断,您希望coordinates两个数组,每个数组包含五个int元素:

int coordinates[2] [5]

Such an initializer used in an array declaration 数组声明中使用的此类初始化程序

{x1,x2,x3,x4,x5}

corresponds to a one-dimensional array that has at least 5 elements. 对应于具有至少5个元素的一维数组。 However this declaration 但是这个声明

int coordinates[5] [2] = { /*...*/ }; 

corresponds to an array elements of which are one-dimensional arrays of the type int[2] . 对应于一个数组元素,该数组元素是int[2]类型的一维数组。 So you may use an initializer list at most with two initializers to initialize each element of the two-dimensional array. 因此,您最多可以使用带有两个初始化程序的初始化程序列表来初始化二维数组的每个元素。

It seems that what you need is the following 似乎您需要的是以下内容

int coordinates[5] [2] = 
{
    { x1, y1 }, 
    { x2, y2 }, 
    { x3, y3 }, 
    { x4, y4 }, 
    { x5, y5 } 
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 聚合初始化程序中的多余元素 - excess elements in aggregate initializer 数组初始化C ++ char Xcode中的多余元素 - Excess elements in array initializer C++ char Xcode 嵌套std :: array时struct initializer中的多余元素 - Excess elements in struct initializer when nested std::array C++ 标量初始值设定项中的多余元素 - C++ Excess elements in scalar initializer 数组初始化器中多余元素的填充字节发现以及常见和特殊的编译器行为 - Padding bytes discovery & common and special compiler behavior on excess elements in array initializer 标量初始化程序代码中的多余元素使用gcc但不使用g ++进行编译 - Excess elements in scalar initializer code compiles with gcc but not g++ '结构初始化程序中的多余元素'错误与C ++ 11统一初始化 - 'Excess elements in struct initializer' error with C++11 uniform initialization 使用igraph C库生成具有幂律度分布的网络时,“标量初始化器中的多余元素” - “excess elements in scalar initializer” when using igraph C library to generate a network with power law degree distribution 如何使用初始化列表初始化数组元素? - How to initialize array elements by using initializer list? 使用默认成员初始值设定项初始化std :: array的元素 - Zero-initializing elements of a std::array with a default member initializer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM