#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const int Rows = 5;
const int Cols = 5;
这是声明和使用枚举的正确方法吗?
enum Minesweeper { Mine = '@', Blank = '*', Loss = 'X'};
void StudentInfo ( );
void Information ( );
void make_board (Minesweeper Board [][Cols], int Rows, int mines);
int main ( )
{
StudentInfo ( );
Minesweeper Board [Rows][Cols];
int mines = 0;
cout << " Enter amount of mines (5 - 10): ";
cin >> mines;
Information ( );
make_board (Board, Rows, mines);
return 0;
}
如何让这个函数输出初始化字符而不是输出整数?
void make_board (Minesweeper Board [][Cols], int Rows, int mines)
{
for (int i = 0; i < Rows; i++)
{
for (int j = 0; j < Cols; j++)
{
Board [i][j] = Blank; // outputs the integer 42
cout << Board [i][j] << ' ';
}
cout << endl;
}
return;
}
这是我目前得到的输出
42 42 42 42 42
42 42 42 42 42
42 42 42 42 42
42 42 42 42 42
42 42 42 42 42
如有任何帮助,我们将不胜感激。谢谢
最佳答案
试试这个:
cout << static_cast<char>(Board [i][j]) << ' ';
关于c++ - 如何正确显示此枚举类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29664038/