Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to ‘true’ and 0 turns to ‘false’? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I’m a pedant. 🙂
Share
How about using the C++ language itself?
UPDATE:
If you want more than 4 lines of code without any console output, please go to cppreference.com’s page talking about
std::boolalphaandstd::noboolalphawhich shows you the console output and explains more about the API.Additionally using
std::boolalphawill modify the global state ofstd::cout, you may want to restore the original behavior go here for more info on restoring the state ofstd::cout.