2维度传递(缺少下标,大小未知)
2 Dimension Passing (missing subscript, unknown size)
我经常得到缺少的下标和未知大小问题。因此,我猜这是一个初学者的问题,但我无法围绕它。如何使我的功能工作并输出到屏幕上?
我试图让两个列充满数字。列[0]由RAND((输入,然后通过方程将列[1]转换为新数字。我希望将1-10行分进。
// function prototypes
void arrayProgram(double ma[][2], int xSize);
int main()
{
const int arraySize = 5;
double ma[arraySize][arraySize];
// if I change double ma[1][2];
// I get an argument of type 'int' is incompatible of type "double(*)[2]
arrayProgram(ma, arraySize);
}//end main
void arrayProgram(double ma[][2], int xSize)
{
int i = 0;
for (i = 0; i < xSize; ++i)
{
ma[i][0] = rand();
ma[i][1] = (ma[i][0] * (20 / 25.0) + 64);
}
}
它工作:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
// function prototypes
void arrayProgram(double ma[][2], int xSize);
int main()
{
const int arraySize = 1;
double ma[arraySize][2];
srand ( time(NULL) ); // setting seed value
rand(); // first random number
arrayProgram(ma, arraySize);
}//end main
void arrayProgram(double ma[][2], int xSize)
{
int i = 0;
for (i = 0; i < xSize; ++i)
{
ma[i][0] = rand();
ma[i][1] = (ma[i][0] * (20 / 25.0) + 64);
std::cout << ma[i][0] << 't' << ma[i][1] << std::endl;
}
}
相关文章:
- 尝试通过多个向量访问变量时,向量下标超出范围
- 矢量下标超出SFML游戏中的范围
- 如何在C++程序中使用下标数字?
- 一组值的零开销下标运算符
- 运行时错误:矢量下标超出范围:正在检查空集
- 如何重载下标运算符 [] 以引用 2d STL 数组?
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 矢量无效下标.SFML
- C++ IDE 不会推断/自动完成对模板类中的 std::array 下标表达式的成员访问
- 编译期间矢量下标超出范围
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 有什么理由不扩展 std::set 以添加下标运算符吗?
- 在继承的模板类中使用下标 [] 运算符
- 对矢量来说是全新的.矢量下标超出范围
- 运算符重载多个任务的下标和赋值运算符
- 为什么函数的任何索引处的下标运算符在C++中总是返回1
- c++下标运算符到下级类向量
- C++十进制到十六进制(字符串下标超出范围)
- 创建结构体向量,表达式:向量下标超出范围
- 2维度传递(缺少下标,大小未知)