gpt4 book ai didi

c++ - 我可以在C++中扩展条件表达式吗

转载 作者:行者123 更新时间:2023-12-02 09:57:43 29 4
gpt4 key购买 nike

如果满足以下条件,我是否可以使用多个条件表达式:
休闲状况:

int number = 50;
if (number > 23) cout << "The variable number is greater then 23 " << endl;
else cout << "23 is greater then variable number" << endl;
条件表达式:
 int number = 50;
cout << (number > 23 ? "The variable number is greater then 23 " : "23 is greater then variable number")<< endl;

在第二种情况下是否可以添加更多的“else if”,或者仅添加由“if and else”组成的一个条件

最佳答案

else if类似,您可以将else情况设为另一种条件:

condition1 ? val1 :
condition2 ? val2 :
condition3 ? val3 :
val4
这相当于
if (condition1)
val1
else if (condition2)
val2
else if (condition3)
val3
else
val4

关于c++ - 我可以在C++中扩展条件表达式吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64412650/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com