Created
October 6, 2016 15:50
-
-
Save yalue/2c7cdb2ed10e0dceea1908d23f908753 to your computer and use it in GitHub Desktop.
How to make using C++ suck less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void StreamPrintf(std::ostream stream, const char *format, ...) { | |
char buffer[1024]; | |
va_list args; | |
memset(buffer, 0, sizeof buffer); | |
va_start(args, format); | |
vsnprintf(buffer, (sizeof buffer) - 1, format, args); | |
va_end(args); | |
stream << buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lol! Making C++ worse than C doesn't require any code at all!
(I think I wrote this way back when I was needing to print a bunch of lines containing both base-10 and hex values.
"0x%08x: %d", a, b
was, and always will be, far more convenient than... << "0x" << std::setfill('0') << std::setw(8) << std::hex << a << std::dec << " " << b
)