Problems with case 'p' || 'P': syntax within a switch statement in C++

前端 未结 3 859
有刺的猬
有刺的猬 2021-01-13 23:33

I\'ve used the switch statement the following way:

   switch (ch){
   case \'P\' || \'p\': 
        goto balance;
        break;

   case \'r\' || \'R\':
           


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 00:03

    case 'P' || 'p': 
        ...
    

    was meant to be:

    case 'P':
    case 'p':
        ...
    

    Note that there is another (in this case more reasonable) approach you could use:

    switch ( std::tolower(ch) ) {
    case 'p': 
         ...
         break;
    case 'r':
         ...
         break; 
    
    default:
         ...
    }
    

    you'll just have to #include

提交回复
热议问题