用于检查两个值的Case命令 [英] Case command for checking two values

查看:130
本文介绍了用于检查两个值的Case命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看此代码:

char o,t; cin >> o >> t;
switch (o,t)
{
  case 's','g': cout << "Finish"; break;
  default: cout << "Nothing";
}

,你可以看到switch设置为两个值,但是如果命令I不能同时检查它们两者。我该怎么办?有什么办法吗?

as you can see switch is set for two values, but in case command I can not check for both of them at the same time. What should I do? is there any way?

推荐答案

你不能同时切换两个表达式。交换机部分仅编译,因为有一个逗号运算符(只是计算为第二个值,在这种情况下 t )。

You cannot do switch for two expressions at the same time. The switch part only compiles because there is a comma operator (which simply evaluates to the second value, in this case t).

使用简单的如果语句。

这篇关于用于检查两个值的Case命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆