ccplusplus.com
Learn C, C++ Concepts
Friday, April 27, 2012
ternary operator c++ example
/******************************************************************* * File : ternary-operator.cpp * Author : blog@ccplusplus * Description : ternary operator c++ example * Date : AM 01:13 27 April 2012 * Source : http://www.ccplusplus.com/p/c_15.html * Note : *******************************************************************/ #include
#include
#include
// for string class using namespace std; int main () { int nFirst, nSecond; cout << "Enter two integers." << endl; cout << "First" << setw (3) << ": "; cin >> nFirst; cout << "Second" << setw (2) << ": "; cin >> nSecond; string strMessage = nFirst > nSecond ? "First is greater than Second" : nFirst < nSecond ? "First is less than Second" : "First and Second are equal"; cout << strMessage << endl; return 0; } /* * * [blog@ccplusplus ternary_operator]$ c++ ternary-operator.cpp -o ternary-operator [blog@ccplusplus ternary_operator]$ ./ternary-operator Enter two integers. First : 10 Second: 20 First is less than Second [blog@ccplusplus ternary_operator]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment