如何正确显示此枚举类型

How can I properly display this enumeration type?

本文关键字:枚举 类型 显示 何正确      更新时间:2023-10-16
#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]) << ' ';