赋给c++中对象类项的枚举值
Enum values assigned to the object class entries in c++
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace System;
using namespace std;
class gate
{
public:
enum mod {single=12,local,global} type;
}gatearry[9];
通过重复赋值枚举值
gatearry[1].type=gate::global;
gatearry[2].type=gate::single;
代替上面的代码。
分配问题枚举值到对象类条目。
困难在于在main
中使用cin
。
for(i=0;i<9;i++)
{
cin>>gatearry[i].type;
}
"此代码是用Visual Studio 10编写的"
目标:减少循环中的命令的分配对象类
的枚举元素或类似且更紧凑的代码,例如循环中的命令
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace System;
using namespace std;
class gate
{
public:
enum mod {single,local,global} type;
}gatearry[9];
int main()
{
int i,x=0;
string d;
for(i=0;i<9;i++)
{
cout<<"n input gate type"<<i<<"n";
cin>>d;
if (d=="single")
gatearry[i].type=gate::single;
else if(d=="local")
gatearry[i].type=gate::local;
else if(d=="global")
gatearry[i].type=gate::global;
if(gatearry[i].type==gate::global)
x++;
cout<<"n"<<gatearry[i].type;
}
cout<<"n"<<x;
return 0;
}
相关文章:
- 不带大括号的枚举形式
- 枚举环境变量的惯用C++14/C++17方法
- 类似枚举的计算常量
- 如何正确实现和访问运算符的各种自定义枚举器
- 错误:从"int"到枚举c++的转换无效
- C++中构造函数中的枚举
- 访问在 C++ 结构中声明的枚举变量
- 枚举类'classname'的多重定义
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- typedef 枚举和枚举类有什么区别?
- 为什么我的开关/机箱在使用枚举时默认?
- 标准::可选枚举的比较运算符
- C++两个源文件之间共享的枚举的静态实例
- 打印没有铸件的枚举可以在C++中吗?
- 枚举成员与静态 int 成员?
- C++:枚举:错误:应使用标识符而不是"}"
- 带有 c++ 的枚举(输入检查)
- 在 qml 中使用 Q_ENUM 和 Q_PROPERTY 作为枚举类
- 为什么 int 类型的枚举类值不能用作 int
- 在 C++ 中输出枚举类类型的向量元素