cout << (c == 5+1 ? 4 : 3) << '\n';
Note that you must put the ?: expression in parentheses. That's because << has higher precedence than ?: and == Without the parentheses, the compiler would evaluate the expression like as if it were written like this: ((cout << c) == 5+1) ? 4 : (3 << '\n');