【C++】枚举量注意
2015-10-19 12:38
549 查看
#include<iostream> #include<string> //头文件是string而不是cstring!! //enum {c,C,p,P,t,T,g,G}; //定义常量,cin无法识别枚举类型,因此应输入整数。如输入0;代表c。枚举量提升为int类型 int main() { using namespace std; char ch; string strc="carnvore",strp="pianist",strt="tree",strg="game"; cout <<"Please enter one of the following choices :\n"; cout <<"c) "<<strc<<"\t\tp) "<<strp<<endl; cout <<"t) "<<strt<<"\t\t\tg) "<<strg<<endl; cin >>ch; while(ch!='c'&&ch!='C'&&ch!='p'&&ch!='P'&&ch!='t'&&ch!='T'&&ch!='g'&&ch!='G') { cout <<"Please enter a c, p, t or g:"; cin >>ch; } cout <<"A maple is a "; switch(ch) { case 'C' : case 'c' : cout <<strc;break; case 'p' : case 'P' : cout <<strp;break; case 'T' : case 't' : cout <<strt;break; case 'G' : case 'g' : cout <<strg;break; } cout <<"."<<endl; return 0; }
相关文章推荐
- C语言中函数参数入栈的顺序
- 链表c++实现
- C++类的底层机理
- 【温故知新C/C++/opencv】取址符&||cv::groupRectangles||引用与值传递
- 理解C++ dynamic_cast
- C++静态库与动态库(转载)
- 乘法口诀表的输出(改)
- VS使用c++的动态链接库
- c语言的文件操作
- C++中4中类型转换的区别
- 1004. 成绩排名 (20)
- C++空类占用内存的问题
- c++ map 根据值的顺序返回排好的键值数组
- C static 函数与变量
- C++ time_t与string之间转换的工具类
- C语言学习笔记
- Leetcode Subsets II
- C++知识点整理——持续更新
- Effective modern C++ 条款 40:注意不同线程句柄的析构函数的行为
- 一个C++ 发送邮件的类