通过多维阵列迭代问题
trouble iterating through multidimensional array
问题是编写一个函数,该函数在二维平面中返回一组点的边界矩形。大小是两个。我知道这些要点将以这种格式{double,double}出现,我知道如何创建边界矩形。不过,我似乎无法获得积分。我尝试了这样的迭代。
Rectangle2D getRectangle(const double points[][SIZE], int s) {
for (int i = 0; i < s; i++) {
for (int j = 0; j < SIZE; j++) {
cout << points[s][SIZE] << endl;
}
}
// will put these points in after i figure out the iteration.
Rectangle2D rekt(x, y, width, height);
return rekt;
}
您每次都访问相同的元素,因为S和大小保持恒定。您必须像此points[i][j]
一样访问它。而且我不确定,但是我认为您不能在数组参数中传递大小,您应该将其作为附加参数传递。祝你好运;)
在这里你去。
for (int i = 0; i < s; i++) {
for (int j = 0; j < SIZE; j++) {
cout << points[i][j] << endl; //observe i,j
}
}
在上面的情况下,您正在迭代行。如果您想迭代列,那么以下将有效。
for (int j = 0; j < SIZE; j++) {
for (int i = 0; i < s; i++) {
cout << points[i][j] << endl; //observe i,j
}
}
相关文章:
- ESP8266单片机矢量迭代器的C++问题
- 在C++中迭代 STL 集时出现奇怪的问题<CStudent>
- 使用基于范围的循环迭代矢量时出现问题
- 成员函数中的迭代器出现问题
- 迭代器的指针操作问题
- 为什么在这个C++问题中使用const_iterator而不仅仅是迭代器?
- 如何解决我们必须向前和向后迭代的项链断裂问题
- 在c++中擦除后在映射上迭代时出现的奇怪问题
- std::filesystem::directory_迭代器链接器问题(C++17)
- C++ 迭代后销毁对象的问题
- 面对迭代矢量<矢量<string>>和打印数据的问题
- 使用 find() 通过 std::set 的迭代器将不起作用。出了什么问题?
- 无法取消引用超出范围的向量迭代器 - 有什么问题?
- 调用模板函数的问题"No matching function for call"参数:迭代器、对象函数
- 迭代快速排序方法的分区算法问题
- 迭代器的问题
- 我通过迭代加法将二进制数转换为十进制并检查单个字符(请参阅代码)的方法有什么问题?
- 实施迭代类别的问题
- 通过多维阵列迭代问题
- GPU 如何帮助改进迭代问题