C++枚举型变量用法
2013-11-04 18:35
225 查看
#include <iostream>
#include <string>
using namespace std;
int main()
{
enum name{one,two=23,three};
//强制类型转换
int a=one;
cout<<a<<endl;
//不能这样直接赋值
//one=10;
//枚举变量赋值
name test=two;
cout<<test<<endl;
//强制类型转换
name myname=name(10);
cout<<myname<<endl;
return 0;
}
#include <string>
using namespace std;
int main()
{
enum name{one,two=23,three};
//强制类型转换
int a=one;
cout<<a<<endl;
//不能这样直接赋值
//one=10;
//枚举变量赋值
name test=two;
cout<<test<<endl;
//强制类型转换
name myname=name(10);
cout<<myname<<endl;
return 0;
}
相关文章推荐
- C++全局变量工程用法
- c++多个源文件共用一个全局变量(extern 的用法)
- C++ 复合数据类型--枚举型用法深解
- c++作用域运算符用法(全局变量和局部变量)
- c++多个源文件共用一个全局变量(extern 的用法)
- C/C++变量的分类,static的用法
- C/C++中static变量和static函数的用法
- C++智能指针作为成员变量的用法
- c++中const基本用法(常变量、常指针、常对象)
- C++ 静态局部变量用法详解
- C/C++中static变量和static函数的用法
- c++多个源文件共用一个全局变量(extern 的用法)
- c++多个源文件共用一个全局变量(extern 的用法)(
- C/C++中static变量和static函数的用法
- C/C++中static变量和static函数的用法
- c++多个源文件共用一个全局变量(extern 的用法)
- [C++] C++中const修饰指针,变量, 函数参数和函数返回值的用法总结
- C++ 一些CString变量的用法技巧总结
- c/c++中extern、static、const的用法及全局变量/常量
- C/C++中static的用法全局变量与局部变量