Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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++ Can';t在我的矩阵中插入符号_C++_Visual Studio - Fatal编程技术网

C++ Can';t在我的矩阵中插入符号

C++ Can';t在我的矩阵中插入符号,c++,visual-studio,C++,Visual Studio,我在这里写了一个矩阵,它很好地出现在屏幕上,但我想把符号放进去。我似乎无法让符号(X)出现在其中。抱歉,这是我第一次使用阵列 #include <iostream> #define WIDTH 70 #define HEIGHT 20 using namespace std; void main () { char world[HEIGHT][WIDTH]; // draws matrix for ( char i = 0; i < HEIGH

我在这里写了一个矩阵,它很好地出现在屏幕上,但我想把符号放进去。我似乎无法让符号(X)出现在其中。抱歉,这是我第一次使用阵列

#include <iostream>
#define WIDTH 70    
#define HEIGHT 20
using namespace std;

void main ()
{
    char world[HEIGHT][WIDTH];
    // draws matrix
    for ( char i = 0; i < HEIGHT; i++ ) {
            for ( char j = 0; j < WIDTH; j++ ) {
                world[i][j] = '.';
                cout << world[i][j];
            }
            cout << endl;
    }
    // 1st symbol at coordinates 1, 1
    int x, y;
    x = 1, y = 1;
    world[x][y] = 'x';
    cout << world[x][y];

    // 2nd symbol at coordinates 2, 2
    x = 2, y = 2;
    world[x][y] = 'x';
    cout << world[x][y];

    //so on..
#包括
#定义宽度70
#定义高度20
使用名称空间std;
空干管()
{
字符世界[高度][宽度];
//绘制矩阵
对于(字符i=0;i
,然后再次循环并将其全部打印出来。

那么发生了什么?你不能
coutStyle注意:它是
int main
,而不是
void main
;最好使用
std::vector
#define
常量不好。另外,<代码> x=1,y=1;非常不常见,但实际上并不适用,最好使用分号来实现它的目的。此外,最好使用<代码> int >代码>索引,而不是<代码> char < /代码>。一旦超过<>代码>宽度< />代码>和/或<代码>高度> />代码(1 char=8位C++实现),您的代码将进入实现定义的行为(至少)。一旦超过28,您将进入未定义的行为。@Luchian Grigore是的:(我会尝试修复它)
12