在c中的2d数组的末尾添加额外的数据列
Adding an extra column of data at the end of a 2d array in c
如何从一个数组中添加数据并将其作为预先存在的数组上的列。
example
double array[3][2];
印刷时:
3 2
5 5
7 8
还有另一个数组里面有其他信息
double arrayb[3]={1,1,1};
我想运行for循环,并能够打印
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
cout << array[i][j];}}
,这是我想看到的:
3 2 1
5 5 1
7 8 1
试试这个:
for (int i=0; i<3; i++) {
// You have only two elements in array[i], so the limit should be 2
for (int j=0; j<2; j++) {
// Leave some whitespace before the next item
cout << array[i][j] << " ";
}
// Now print the element from arrayb
cout << arrayb[i] << endl;
}
似乎最明显的方法是:
for (int i=0; i<3; i++) {
for (int j=0; j<2; j++)
std::cout << array[i][j] << 't';
std::cout << arrayb[i] << 'n';
}
相关文章:
- 我可以在 C++ 中将数据成员/变量从其定义之外添加到结构中吗?
- 如何使用 Google Test 向测试添加元数据 / 如何将数据从 Google Test 发送到 TestEven
- 将私有数据成员添加到野牛生成的类中
- 可变参数模板与使用元组在参数中添加不同的数据对
- 在PROGMEM中添加更多数据会中断Arduino Mega 2560上的SPI传输
- 在 2D 矢量数组中的特定标头下添加数据
- 使用模板参数添加数据
- 如何在结构中动态添加数据,这是指向指针数组的指针
- 如何在数组 QT C++中添加数据
- 插入时对对象进行排序(若存在,则添加数据)
- 在链接列表中添加数据
- 使用python解析或读取CPP文件,并通过忽略CPP文件注释来添加数据
- 跟踪何时为增强序列化添加数据成员
- 如何在c++中使用单链表对象显示和添加数据
- 在c++中向结构体addrinfo中添加数据
- 从另一个基类向结构体添加数据成员
- 如何添加数据到椭圆QT
- 写波头和添加数据,不关闭流
- 使用c++检查和添加数据到protobuff中
- 如何在c++中添加数据结构到动态链接库