C++ 蛇和梯子,编号块

C++ 蛇和梯子,编号块,c++,graphics,C++,Graphics,我在做一个蛇和梯子的游戏。我将屏幕分为10条水平线和10条垂直线,但我发现的下一个问题是具体插槽的编号 使用outextxy()函数,我只能显示特定的数字,尝试使用数组将无法工作: int a[100]; for(i=0;i<100;i++) { a[i]=i; outtextxy( x,y,a[i]); } inta[100]; 对于(i=0;i如果我正确理解了您的问题,您需要将整数转换为字符串,然后再将其交给outtextxy,因此您需要类似以下内容: int a[1

我在做一个蛇和梯子的游戏。我将屏幕分为10条水平线和10条垂直线,但我发现的下一个问题是具体插槽的编号

使用outextxy()函数,我只能显示特定的数字,尝试使用数组将无法工作:

int a[100];
for(i=0;i<100;i++)
{
    a[i]=i;
    outtextxy( x,y,a[i]);
}
inta[100];

对于(i=0;i如果我正确理解了您的问题,您需要将整数转换为字符串,然后再将其交给
outtextxy
,因此您需要类似以下内容:

int a[100];
char output[MAX_OUTPUT_SIZE]; // For 0 to 99, MAX_OUTPUT_SIZE = 5 is more than enough
for(i=0;i<100;i++)
{ 
   a[i]=i;
   sprintf( output, "%d", i );
   outtextxy( x,y,output);
}

其基本思想是:

int rows = 10;
int cols = 10;

for(int r = 0; r < rows; ++r){
 for(int c = 0; c < cols; ++c){
   cout << r << ", " << c;
   if(c != cols-1) cout << " ";
 }
cout << endl;
}
int行=10;
int cols=10;
对于(int r=0;r你的意思是什么:
我发现的下一个问题是特定插槽中的“否”
?你是在问如何给这个“网格”中的每个单元格编号吗“当然,,,,我一直在努力工作,但没有进展。为什么不将int转换成字符串并打印出来呢?使用sprintf或itoa。我已经对你的帖子进行了一些格式化,但请注意代码格式。此外,在问题中添加更多的”?“也不会让你更快地得到答案。现在,我们到底为什么需要
int
array for?:)我假设OP计划稍后使用它。也许这不是他的本意。我会补充一点。使用该数组只是一种显示我在显示int值(不一定是1-100)时所面临问题的方法。还有一件事……你能告诉我@DavidIt的%d在解释输入时是怎么说的吗(
I
)作为十进制整数。例如,如果使用
%x
,它将使表示输入的字符串为十六进制。
char output[MAX_OUTPUT_SIZE]; // For 0 to 99, MAX_OUTPUT_SIZE = 5 is more than enough
for(i=0;i<100;i++)
{ 
   sprintf( output, "%d", i );
   outtextxy( x,y,output);
}
int rows = 10;
int cols = 10;

for(int r = 0; r < rows; ++r){
 for(int c = 0; c < cols; ++c){
   cout << r << ", " << c;
   if(c != cols-1) cout << " ";
 }
cout << endl;
}
cout << arr[r][c]; // you should understand the difference between row-major / column major
cout << arr[ (r * cols) + c ]