首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

switch语句请问

2012-02-11 
switch语句请教CString str张三int age0switch(str){case 李四:age20breakcase 马六:age21

switch语句请教
CString str="张三";
int age=0;
switch(str)
{
case "李四":age=20;break;
case "马六":age=21;break;
}
  MessageBox("ok!",NULL,MB_OK);


为什么老出错呢?

[解决办法]
Switch不支持字符串的。
[解决办法]
CString strArr[5]={"AB","CD"..};
int index=Find(str);
switch(index)
case 0:..
case 1:..
[解决办法]
case只能匹配整数性质的类型
[解决办法]
find是泛型算法里面的函数要用头文件
#include<algorithm>
[解决办法]

探讨
switch只能支持常数

[解决办法]
switch(表达式)
表达式类型为整型,字符型,或枚举型!

热点排行