Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从打印函数打印二维阵列时出现的问题_C++_Function_Multidimensional Array - Fatal编程技术网

C++ 从打印函数打印二维阵列时出现的问题

C++ 从打印函数打印二维阵列时出现的问题,c++,function,multidimensional-array,C++,Function,Multidimensional Array,我试图用2d数组填充和打印,但每次我都试图编译它 表示未声明的标识符c。并在打印功能中将箭头指向c。 我尝试了多种方式来声明它,但由于某种原因,它不会起作用 #include <iostream> using namespace std; void print(char x[][c], int r) { for(int r = 0; r < 25; r++) { for(int c = 0; c < 25; c++)

我试图用2d数组填充和打印,但每次我都试图编译它 表示未声明的标识符c。并在打印功能中将箭头指向c。 我尝试了多种方式来声明它,但由于某种原因,它不会起作用

#include <iostream>

using namespace std;

void print(char x[][c], int r)
{
    for(int r  = 0; r < 25; r++)
    {
        for(int c = 0; c < 25; c++)
        {
          cout << x[r][c]; 
        } 
        cout << endl;    
    } 
}

int main()
{
    void print(char x[][c], int r);

    char p[25][25];

    for(int r = 0; r < 25; r++)
    {

        for(int c = 0; c < 25; c++)
        {
            if(r==0)p[r][c]='x';
            else    p[r][c]='o';
        }    
    }   

    print(p[25][25]);


    return(0);
}
#包括
使用名称空间std;
无效打印(字符x[][c],整数r)
{
对于(int r=0;r<25;r++)
{
对于(int c=0;c<25;c++)
{
试试这个:

#include <iostream>

using namespace std;

void print(char x[25][25])
{
    for(int r  = 0; r < 25; r++)
    {
        for(int c = 0; c < 25; c++)
        {
          cout << x[r][c]; 
        } 
        cout << endl;    
    } 
}

int main()
{
    char p[25][25];

    for(int r = 0; r < 25; r++)
    {
        for(int c = 0; c < 25; c++)
        {
            if(r==0)p[r][c]='x';
            else    p[r][c]='o';
        }    
    }   

    print(p);

    return(0);
}
#包括
使用名称空间std;
作废打印(字符x[25][25])
{
对于(int r=0;r<25;r++)
{
对于(int c=0;c<25;c++)
{

不能用下面的方法写

#include <iostream>

using namespace std;


const size_t ROWS = 25;
const size_t COLS = 25;

void print(char x[][COLS], size_t r )
{
    for ( size_t i  = 0; i < r; i++ )
    {
        for ( size_t j = 0; j < COLS; j++ )
        {
          cout << x[i][j]; 
        } 
        cout << endl;    
    } 
}

int main()
{
    char p[ROWS][COLS];

    for ( size_t i = 0; i < ROWS; i++ )
    {
        for ( size_t j = 0; j < COLS; j++ )
        {
            if ( i == 0 ) p[i][j] = 'x';
            else p[i][j] = 'o';
        }    
    }   

    print( p, ROWS );


    return(0);
}
void print( char ( &x )[ROWS][COLS] )
{
    for ( size_t i  = 0; i < ROWS; i++ )
    {
        for ( size_t j = 0; j < COLS; j++ )
        {
          cout << x[i][j]; 
        } 
        cout << endl;    
    } 
}

使用未声明的标识符
c
什么是c??无效打印(char x[][c],int r)??在这一行中,无效打印(char x[][c],int r);什么是char x[][c]?特别是“c”?试着理解编译器错误。你没有声明c。这是什么?你的代码在这么多级别上都是错误的…你想实现什么?你能写出你想要的输出吗?你能解释另一种方法吗?我不知道
char(&x)[ROWS][COLS]
@itsnotmyrealname它是对2D数组引用的声明。例如,如果您有一个声明int x=10;那么对x的引用声明为int&rx=x;如果您有一个1D数组int a[10];那么对数组的引用声明为int(&ra)[10]=a;
    print( p );