#ifndef _SWITCH_CASE_INIT_
#define _SWITCH_CASE_INIT_
#define _SWITCH(X) {char *__switch_p__;\
int __switch_next__;\
for(__switch_p__ = X ? (char *)X : NULL; \
__switch_p__;\
__switch_p__ = NULL ,__switch_next__ = 1)\
{{
#define _CASE(X) } if(!__switch_next__ || \
!(__switch_next__ = strcmp(__switch_p__, X))) {
#define _DEFAULT } {
#define _END }}}
#endif
int main(void)
{
char pname[20] = {0};
std::cin >> pname;
_SWITCH(pname)
_CASE("lijh")
std::cout << "this is lijh" << std::endl;
break;
_CASE("baiyf")
std::cout << "this is baiyf" << std::endl;
break;
_END
}
编译运行
ubuntu@VM-0-16-ubuntu:~/lijh/cc$ ./T1
lijh
this is lijh