C++: Ways of printing "Yes" and "No" answers

Revision en3, by seul, 2020-04-04 18:36:11

Level 1:

if(flag == 1) cout << "YES"; else cout << "NO"; cout << endl;

Level 2:

cout << (flag == 1 ? "YES" : "NO") << endl;

Level 3:

This one just came to me while reading this amazing blog by HosseinYousefi.

cout << "YES\0NO\0" + 4 * (flag == 0) << endl;

Please share other "YES-NO" one-liners you know. Will add it to this list.

Tags c++, tips-and-tricks

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en16 English seul 2020-04-14 21:56:31 36
en15 English seul 2020-04-05 19:05:54 16
en14 English seul 2020-04-05 16:56:19 326 Tiny change: 'g curve:\n[user:ye' -> 'g curve:\n\n[user:ye'
en13 English seul 2020-04-05 09:25:57 207 Tiny change: 'Level 4:**\n\n(by [user:' -> 'Level 4:** (by [user:'
en12 English seul 2020-04-05 00:49:12 55
en11 English seul 2020-04-05 00:47:41 65 Reverted to en9
en10 English seul 2020-04-05 00:35:19 65
en9 English seul 2020-04-05 00:26:36 4
en8 English seul 2020-04-05 00:22:24 120
en7 English seul 2020-04-05 00:19:39 122 Tiny change: ';\n~~~~~\n[user:ch' -> ';\n~~~~~\n\n### **Level 4:**\n\n[user:ch'
en6 English seul 2020-04-04 22:02:19 20
en5 English seul 2020-04-04 19:26:45 88
en4 English seul 2020-04-04 19:01:30 60
en3 English seul 2020-04-04 18:36:11 86 (published)
en2 English seul 2020-04-04 18:32:20 24
en1 English seul 2020-04-04 18:29:09 481 Initial revision (saved to drafts)