c++ - 如何正确显示此枚举类型?

标签 c++ c++11

#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/

相关文章:

c++ - 随机数正态分布挂程序?

c++ - C++ STL 中 max_element 和 minmax_element 的行为差异

c++ - 默认情况下,final 类的方法是否应用于函数指针优化?

c++ - 如何从文件 C++ 中读取带有科学记数法的 float ?

c++ - Qt 添加扩展 QGraphicsItem 到场景

c++ - 未初始化的变量有什么危险?

c++ - 具有共享资源的 D3DX11SaveTextureToFile

C++:按位与

c++ - libcxx 中 std::is_function 的实现如何工作?

c++ - "Moving out"对象的内部表示。好不好?