如何正确显示此枚举类型
How can I properly display this enumeration type?
#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]) << ' ';
相关文章:
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 如何注册枚举类型到QJSEngine,以便在脚本环境中使用?
- 通过包装器从 C 访问C++ API 时,如何访问枚举类型
- C++/错误:表达式必须具有整数或无作用域枚举类型
- 如何理解c++中在命名空间内部定义的枚举类型enum
- 在类访问混淆中声明的枚举类型
- 在枚举类型上使用std::max是不是一种糟糕的做法
- C++ 在方程中使用变量;错误:表达式必须具有整数或无作用域枚举类型及其他
- 是否可以使用泛型枚举类型作为函数的参数?
- Visual Studio 2017 生成工具与枚举类型的问题
- 使用枚举类型管理存储顺序
- 如何检查类中定义的枚举类型变量是否被分配给?
- 如何从枚举类型中获取枚举值?
- 为什么C++不为枚举类型提供默认"operator>>"函数?
- 确保枚举类型的键/值在软件Revs之间永远不会更改
- MSVC 1 位枚举类型等于 -1,并且相等性测试失败
- 我们可以专业化类模板的枚举(类型)成员吗?
- 错误:以增量方式填充向量时,表达式必须具有整数或无作用域枚举类型
- 枚举类型的重载>>运算符(工作日)
- C 中的枚举类型字符串类别