相关疑难解决方法(0)

为什么switch语句不能应用于字符串?

编译以下代码并得到错误type illegal.

int main()
{
    // Compilation error - switch expression of type illegal
    switch(std::string("raj"))
    {
    case"sda":
    }
}
Run Code Online (Sandbox Code Playgroud)

你不能在任何一个switch或中使用字符串case.为什么?是否有任何解决方案可以很好地支持类似于切换字符串的逻辑?

c++ string switch-statement

208
推荐指数
10
解决办法
33万
查看次数

单引号与C或C++中的双引号

我应该何时在C或C++编程中使用单引号和双引号?

c c++ syntax char string-literals

190
推荐指数
10
解决办法
13万
查看次数

标签 统计

c++ ×2

c ×1

char ×1

string ×1

string-literals ×1

switch-statement ×1

syntax ×1