C++ 类型为“的参数”;int";与参数类型“不兼容”;int**;

C++ 类型为“的参数”;int";与参数类型“不兼容”;int**;,c++,C++,我正在编写一个2d数组程序,在打印出来时遇到了问题,我不确定我的2d数组现在是否正确通过,因为它正在崩溃,而不是运行。任何建议都会有帮助 void initialize(int* one, int** two); void replace(int* arr,int rows, int cols,int value); void fill(int* arr, int rows, int cols); void print(int** arr, int rows, int cols); ofstr

我正在编写一个2d数组程序,在打印出来时遇到了问题,我不确定我的2d数组现在是否正确通过,因为它正在崩溃,而不是运行。任何建议都会有帮助

void initialize(int* one, int** two);
void replace(int* arr,int rows, int cols,int value);
void fill(int* arr, int rows, int cols);
void print(int** arr, int rows, int cols);

ofstream outfile;
ifstream infile;
int arrayOne[100][100];
int arrayTwo[100][100];

int main(){

    int rows,cols=0;

    cout << "Please input how many rows you would like in the array:  ";
    cin >> rows;
    cout << "Please input how many columns you would like in the array:  ";
    cin >> cols;

    fill(arrayOne[100][100],rows,cols);
    //print(arrayOne[100][100],rows,cols);

    system("pause");
    return 0;
}

void initialize(int* one, int* two){
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            arrayOne[i][j]=0;
            arrayTwo[i][j]=0;
        }
    }
}

void replace(int* arr,int rows,int cols,int value){
    arr[rows][cols]=value;
}

void fill(int* arr, int rows, int cols){
    int i=0;
    for(int r=0; r < rows; r++){
        for(int c=0; c < cols; c++){
            replace(arr,r,c,i++);
        }
    }
}

void print(int** arr, int r, int c){
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
}
void初始化(int*one,int**two);
无效替换(int*arr,int行,int列,int值);
空洞填充(int*arr、int行、int列);
无效打印(整数**arr、整数行、整数列);
出流孔的直径;
河流充填;
int arrayOne[100][100];
int arrayTwo[100][100];
int main(){
int行,cols=0;
cout>行;
cout>cols;
填充(数组[100][100],行,列);
//打印(数组[100][100],行,列);
系统(“暂停”);
返回0;
}
无效初始化(int*1,int*2){

对于(int i=0;i,如果您阅读了错误消息,它会清楚地说明您的问题。也就是说,它不会清楚地说明如何修复它。使用固定数组,您将走上一条艰难的道路

/* arrayOne[100][100] This is an 'int' at the 101st row and 101st column.
 * It isn't an address to anywhere in the array, in fact it is just beyond
 * the end of your array.
 *
 * Regardless, even if it were a pointer, it would point to a location in memory
 * that is not yours. We count starting with 0 in C/C++. So if you'd like to
 * reference the 'whole' array  just pass it bare:
 */
fill (arrayOne, rows, cols);

/* Of course this means that you need to fix the definition of 'fill'
 * and 'replace'.
 */
void replace(int arr[100][100],int rows,int cols,int value){
    arr[rows][cols]=value;
}

/* As you can see this isn't going to be friendly */
void fill(int arr[100][100], int rows, int cols){
    int i=0;
    for(int r=0; r < rows; r++){
        for(int c=0; c < cols; c++){
            replace(arr,r,c,i++);
        }
    }
}
/*arrayOne[100][100]这是第101行和第101列的“int”。
*它不是数组中任何位置的地址,事实上它只是超出了数组的范围
*数组的末尾。
*
*无论如何,即使它是一个指针,它也会指向内存中的一个位置
*这不是你的。在C/C++中,我们从0开始计算。如果你愿意的话
*引用“整个”数组只需将其裸露传递:
*/
填充(阵列、行、列);
/*当然,这意味着您需要修正“填充”的定义
*和“替换”。
*/
无效替换(int arr[100][100],int行,int列,int值){
arr[行][cols]=值;
}
/*正如你所看到的,这将是不友好的*/
填空(整数arr[100][100],整数行,整数列){
int i=0;
对于(int r=0;r

您还有其他问题,但当您遇到这些问题时,可以在其他问题中询问这些问题。

将所有int*arr和int**arr更改为int-arr[100][]或arr[][100]我不记得是哪一个。但是,这是肯定的。

所有指针自慰,这看起来像C而不是C++。数组与指针不一样。这是你的错误假设,导致很多问题。只使用向量,你会把所有错误都张贴出来,并在注释中添加行数。对于任何人都会感到奇怪。这里的问题是,
fill(arrayOne[100][100],rows,cols);
@chris:还有大约5个问题,比如双重订阅
int*
。是的,我完全搞砸了我的2D数组。谢谢!我以前使用Microsoft Visual Studio 6编译器。我相信你能做到这一点。