把下面if else 改为3重运算符 ?: 的

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:00:31
if(i > 5)
cout << "It's greater than 5" << endl;
else
if(i < 5)
cout << "It's less than 5 " << endl;
else
cout << "It's equal to 5 " << endl;
1楼的 编译不通过
i > 5 ? (cout << "It's greater than 5" << endl;) : ((i < 5) ? (cout << "It's less than 5 " << endl;) : (cout << "It's equal to 5 " << endl;));
我写的依然不通过

(i==5)?(cout << "It's equal to 5 " << endl):(i>5?(cout << "It's greater than 5" << endl):(cout << "It's less than 5 " << endl));

楼主 我现在不是改了吗,就是吧分号去掉就行了,你现在试试

请问楼主用的什么编译器?我用vc6,楼上的可以正确编译运行