**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。
这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
5天前关闭。
Improve this question
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int NUM_ROWS = 5;
const int NUM_COLS = 10;
int array[NUM_ROWS][NUM_COLS]{};
cout << "Array contents:" << endl;
for (int row = 0;row<NUM_ROWS;row++)
{
for (int col=0;col<NUM_COLS;col++)
{
int array[row][col] = rand () % 200;
cout << array[row][col] << setw(2);
}
}
}
的一个字符串
`我想通过使用5行和10列输入一个0-199之间的随机数(总共留下50个随机数值),但我的ide将int值:row和col注册为常规变量,我认为可以调整数组的维度。
2条答案
按热度按时间xqnpmsa81#
不使用“C”风格的数组,看看C++的数组(和基于范围的循环)
字符串
oogrdqng2#
这条线
字符串
int
是无效的语法。前导int
使其成为新局部变量array
的声明(隐藏了main()
第三行的外部声明),但初始化器rand() % 200
对于初始化数组无效,因此您将获得编译器错误。删除前面的
int
,将此声明转换为赋值,程序将编译:型