Help with "?" Operator

I received some sample code. I understand all of it except one specific line. I just don't understand what it does, specifically the "?" and ":". Also, is there an alternative to do what it does.

Thanks

 
  cout << (first == "" ? "eh" : first) << endl;
(expression ? action1 : action 2)

Evaluate the expression, and if the expression yields true, do action1. Otherwise do action2.
Okay, I understand.

Perfect, thank you
1
2
3
4
5
6
if(first == "") // ie if first is blank
   cout << "eh";
else
   cout << first;

cout << endl; // for whatever choice is printed out of the above 
Perfect explanations, thank you all
Last edited on
Topic archived. No new replies allowed.