我正在尝试将2D数组从函数传递到另一个函数.但是,数组的大小不是恒定的.大小由用户决定.
我试图研究这个,但没有太多运气.大多数代码和解释都是针对数组的恒定大小.
在我的函数中,A我声明了变量然后我稍微操作它,然后它必须传递给Function B.
void A()
{
int n;
cout << "What is the size?: ";
cin >> n;
int Arr[n-1][n];
//Arr gets manipulated here
B(n, Arr);
}
void B(int n, int Arr[][])
{
//printing out Arr and other things
}
Run Code Online (Sandbox Code Playgroud)
rig*_*old 11
使用std::vector,如果你想动态调整大小的数组:
std::vector<std::vector<int>> Arr(n, std::vector<int>(n - 1));
B(Arr);
void B(std::vector<std::vector<int>> const& Arr) { … }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7075 次 |
| 最近记录: |