【发布时间】:2012-08-28 22:52:51
【问题描述】:
我想在 C 中使用三元运算符而不使用 else。我该怎么做。
(a)? b: nothing;
类似的东西。我什么都没用?
【问题讨论】:
-
如果您不打算使用 else,为什么要使用三元运算符。它失去了它的目的。
-
我遇到了与 op 相同的问题,
cout << ((isNegative) ? '-') << number将是一个完美的例子,说明当某个条件为真时您想要一个额外的字符,而 else 不能是 '',因为一个字符不能为空。 -
它是什么意思,你想在什么情况下使用它?
-
@user5887651 我想可以使用
(isNegative ? (cout<<',') : cout) << number;...
标签: c operator-keyword if-statement ternary