所以这就是我所拥有的
#include <iostream>
using namespace std;
int createArray(){
int array[10][10] = {0};
int x, y;
int size = 0;
while(x != 0 && y !=0){
cin >> x >> y;
while( x<0 || x>10 || y<0 || y>10){
cout << "error" << endl;
cin >> x >> y;
}
if(x>0 && y >0){
array[x-1][y-1] = 1;
}
if(size < x){
size = x;
}
if (size < y){
size = y;
}
}
return(array, size);
}
int printArray(int array[10][10],int size){
int i, j;
for(i=0; i<size; i++){
for(j=0; j<size; j++){
cout << array[i][j] << " ";
}
cout << endl;
}
return 0;
}
int main() {
/*
What happens here? I thought I could do something like..
auto [arrayA, sizeA] = createArray();
printArray(arrayA, sizeA);
but that's not working
*/
}过去几个小时我一直在胡闹,但一直没起作用。如果我的不同尝试在代码中留下了一些草率的东西,我也不会感到惊讶,但是我的大脑被炸了,哈!这是学校的作业,我还有更多的工作要做,但我似乎做不到。我可以在main()中直接编写它们,它可以工作,但我特别需要使用函数来完成。
发布于 2022-11-03 22:48:44
您不能在c++中这样做。
return(array, size);你可以,但它不能像你想的那样做。它只返回大小(查找逗号操作符)
很多时候,在c++助手中,对于您可以使用和不能使用的东西,有一些愚蠢的规则。
您可以使用std::结对返回2件东西。
我会使用向量向量,而不是固定大小的数组
https://stackoverflow.com/questions/74310310
复制相似问题