Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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+;+;基本数组问题)数组的定义/初始化干扰其他单独数组的定义(visual studio 2015)_C++_Arrays_Visual Studio_Visual C++ - Fatal编程技术网

C++ (C+;+;基本数组问题)数组的定义/初始化干扰其他单独数组的定义(visual studio 2015)

C++ (C+;+;基本数组问题)数组的定义/初始化干扰其他单独数组的定义(visual studio 2015),c++,arrays,visual-studio,visual-c++,C++,Arrays,Visual Studio,Visual C++,如果我们注释掉定义字符数组“croschar”的第二个for循环,则输出是字符“C”,形成字母“C”的形状,长度和宽度为五个字符。当for循环没有注释掉时,没有输出,即终端挂起为空。问题的根源可能是基本的,但我很难理解为什么会发生这种情况,因为在我看来,数组在功能上是分离的 #include <cstdlib> #include <iostream> #include <cmath> void cbanner() { const int row =

如果我们注释掉定义字符数组“croschar”的第二个for循环,则输出是字符“C”,形成字母“C”的形状,长度和宽度为五个字符。当for循环没有注释掉时,没有输出,即终端挂起为空。问题的根源可能是基本的,但我很难理解为什么会发生这种情况,因为在我看来,数组在功能上是分离的

#include <cstdlib>
#include <iostream>
#include <cmath>

void cbanner()
{
    const int row = 5, col = 5;
    const int raw = 5, cal = 5;

    char cchar[row][col];
    char croschar[raw][cal];

        for (int r = 0; r < row; ++r)
    {
        for (int c = 0; c < col; ++c)
        {
            cchar[r][c] = 'C';

            if ((r > 0) && (r < (row - 1)) && (c > 0))
                cchar[r][c] = ' ';
        }
    }


    for (int rr = 0; rr < raw; ++rr)
    {
        for (int cc = 0; cc < cal; ++cc)
        {
            croschar[rr][cc] = 'p';

            if ((rr = (raw / 2)) && (cc = (cal / 2)))
                croschar[rr][cc] = '+';
        }
    }


    for (int r = 0; r < row; ++r)
    {
        for (int c = 0; c < col; ++c)
        {
            cout << cchar[r][c];
         }
            cout << endl;
    }
}
#包括
#包括
#包括
void cbanner()
{
常量int行=5,列=5;
常数int raw=5,cal=5;
char cchar[行][列];
煤焦[生][cal];
对于(int r=0;r0)和((r<(第1行))和((c>0))
cchar[r][c]='';
}
}
对于(int-rr=0;rrcout解决此类问题的正确工具是调试器。在询问堆栈溢出问题之前,您应该逐行检查代码。有关更多帮助,请阅读。至少,您应该[编辑]您的问题,以包括一个重现您的问题的示例,以及您在调试器中所做的观察。而不是if((rr=(raw/2))&&&(cc=(cal/2))),写if((rr==(raw/2))&&&&(cc=(cal/2))。当然,使用调试器。啊,这是非常基本的。很抱歉占用了您的时间。感谢链接,πάνταῥεῖ! 非常感谢你直截了当的回答,t.m。!