关于switch的用法,现在我想实现如下功能:
switch(szCaption)
{
  case "abcd":
     {
      ...
      break;
     }
  case "efhg":
     {
     ...
     break;
     }
  case "ijkl":
   { 
    ...
    break;
    }
}
我这样写的,但编译时会出错,我用什么方法能解决上述问题呢?

解决方案 »

  1.   

    "abcd":不是常量,
    应这样char c;
    switch(c)
    {
    case 'a':
    break;
    ....
    }
      

  2.   

    case 后只能是数字,或char。
    字符串不对。swicth后的条件也一样
      

  3.   

    switch(switch-type switch-name)switch-type:must be an int, char, enum type, or an identifier that resolves to one of these types. 
    switch-name 
      

  4.   

    怎么可以case 字符串呢?
    还是用if else if else结构吧。其实这个也补推荐。字符串最好用strcmp来比较大小。
      

  5.   

    switch 后只能判断数字,而且必须是整数,浮点数也是不行的。所以只要是整型的变量都可以(char, int ,UINT, DWORD,WORD,LONG)
      

  6.   

    switch(c)中的c必须为整型或可以转换为整型的其他数据类型。
      

  7.   

    不能case字符串的,用一个整形量来区别吧