Liam0205 / liam0205.github.io

Deployment of my weblog.
https://liam0205.github.io
35 stars 5 forks source link

在 C++ 中的 switch-case 语句中使用 C 风格字符串 | 始终 #251

Open Liam0205 opened 5 years ago

Liam0205 commented 5 years ago

https://liam.page/2018/11/05/apply-C-style-string-in-switch-case-clause/

众所周知,C/C++ 语言中的 switch-case 语句只支持整型数字的逻辑分支。因此,当我们需要对整型数字之外的变量进行分支判断时,就只能依赖 if-else 语句了。例如: 1234567if (policy == "SINGLE") { ; // do something} else if (policy == "MULTIPLE") { ;