我正在制作一个简单的剪刀石头布游戏,我需要使用枚举数据结构。
我的问题是,由于从 int (userInput) 到 Throws (userThrow) 的转换无效,我无法编译以下代码。
enum Throws {R, P, S};
int userInput;
cout << "What is your throw : ";
cin >> userInput;
Throws userThrow = userInput;
Help?!
你可以这样做:
int userInput;
std::cin >> userInput;
Throws userThrow = static_cast<Throws>(userInput);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)