Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';switch语句中的t表达式是否为字符串?C++;_C++ - Fatal编程技术网

C++ Can';switch语句中的t表达式是否为字符串?C++;

C++ Can';switch语句中的t表达式是否为字符串?C++;,c++,C++,下面的代码返回错误:开关数量不是整数。怎么了 string s = "20"; switch (s){ case "18": cout << "18" << "\n"; break; case "20": cout << "20" << &quo

下面的代码返回错误:开关数量不是整数。怎么了

string s = "20";
  
  switch (s){
    
    case "18":
      cout << "18" << "\n";
      break;
      
    case "20":
      cout << "20" << "\n";
      break;
    
  }
string s=“20”;
开关{
案例“18”:

coutcase
s必须是整数类型和编译时可计算的常量表达式

使用
if
else
块,而不是与语言对抗。或者如果可以使用整型,则执行以下操作:

int n = 20;  
switch (n){    
case 18:
    std::cout << n << "\n";
    break;      
case 20:
    std::cout << n << "\n";
    break;    
}
int n=20;
开关(n){
案例18:

std::coutcase
s必须是整数类型和编译时可计算的常量表达式

使用
if
else
块,而不是与语言对抗。或者如果可以使用整型,则执行以下操作:

int n = 20;  
switch (n){    
case 18:
    std::cout << n << "\n";
    break;      
case 20:
    std::cout << n << "\n";
    break;    
}
int n=20;
开关(n){
案例18:

不能,不能,因为你的案例是数字为什么不使用数字?不,不能,因为你的案例是数字为什么不使用数字?