我的问题是关于枚举,我的代码是:C++枚举
#include<iostream>
using namespace std;
int main()
{
enum bolumler {programcilik,donanim,muhasebe,motor,buro} bolum;
bolum = donanim;
cout << bolum << endl;
bolum += 2; // bolum=motor
cout << bolum;
return 0;
}
输出应该但根据这些代码的错误是:
error C2676: binary '+=' : 'enum main::bolumler' does not define this operator or a conversion to a type acceptable to the predefined operator
Error executing cl.exe.
111.obj - 1 error(s), 0 warning(s)
你能帮忙我呢?另一个问题是,如果我想看到像“muhasebe”这样的输出结果,我该怎么办?
使用编辑器中的源代码按钮,否则很难阅读。 – mingos 2010-04-17 23:19:37
请格式化您的代码。 – jweyrich 2010-04-17 23:19:56
事实上,所有失败的原因是因为即使是枚举,E1 + E2也是E1 = E1 + E2。但'+'内置运算符不会返回枚举类型,所以'+ ='的使用会失败。 – 2010-04-17 23:33:52