error C2050: switch expression not integral

#include<stdio.h>#include <string.h>char* test();void main(){char* cRet = test();printf("Ret value:%s\n", &cRet);printf("retp:%p\n",cRet);if(!strcmp(cRet, "127.0.0.0")){printf("返回值是127.0.0.0\n");}else{printf("不是127.0.0.0\n");}switch(cRet){case "127.0.0.0":printf("返回值是127.0.0.0\n");break;default:printf("返回值不是127.0.0.0\n");break;}}char* test(){return "127.0.0.0";

}

使用strcmp比较可以正常实现,用switch(表达式)则编译无法 通过,报错提示:error C2050: switch expression not integral

这是因为switch的表达式必须是整数,所以能作用在int和比int范围小的数据类型,如:int,short,char,byte可以实现,,而long,string是不行的

吃东西,随便是什么——都可以。当日出越过山涧,我未老,你依然。

error C2050: switch expression not integral

相关文章:

你感兴趣的文章:

标签云: