(C++) "No operator " >> " matches these operands"枚举
(C++) "No operator ">>" matches these operands" with enumeration
所以,我是一个完全的c++语言初学者,我正在做《Beginning c++ Through Game Programming》这本书中的一个练习,特别是第3章的第一个练习。它希望我使用std::cout
和switch
语句创建一个"困难选择程序",但是当我试图使用std::cin
输入枚举类型difficulties
的变量(myDifficulty
)时,我发现了一个问题,在那里我在>>
下得到上面的错误。下面是我的代码:
#include <iostream>
int main()
{
enum difficulties {EASY = 1, NORMAL, HARD, EXTREME};
difficulties myDifficulty;
std::cout << "EasynNormalnHardnExtremen";
std::cin >> myDifficulty;
switch (myDifficulty)
{
case 1:
std::cout << "You have chosen Easy as your difficulty." << std::endl;
break;
case 2:
std::cout << "You have chosen Normal as your difficulty." << std::endl;
break;
case 3:
std::cout << "You have chosen Hard as your difficulty" << std::endl;
break;
case 4:
std::cout << "You have chosen Extreme as your difficulty. Good luck!" << std::endl;
break;
}
system("pause");
return 0;
}
如果有人能帮忙,谢谢你。此外,如果我的代码有任何问题(它看起来如何等)反馈将非常感激!
p。这是我的第一个问题。:)
默认情况下,c++中没有定义enum
类的operator>>
,您需要创建自己的操作符:
std::istream& operator>> (std::istream& in, difficulties& diff) ;
相关文章:
- EASTL矢量<向量<int>>连续的
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C++,错误:" no operator "== " matches these operands ",ostream/istream
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- ``这个''不能用this-&gt;指针变量
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在
- 使用shared_ptr<字符串>转换为一个无序集合<字符串>
- 是numeric_limits&lt; int&gt; :: is_modulo从逻辑上矛盾