Why does the same vsnprintf code output differently on Windows (MSVC) and Unix (Clang)
问题 On Unix (Clang 3.8.1), this code outputs: 6: 32 8: a8e On Windows (MSVC 19.00.24215.1), this code outputs: 6: 12345 6: a12345e #include <iostream> #include <stdarg.h> static std::string getFormattedString(const char* fmt, va_list ap) { int count = vsnprintf(NULL, 0, fmt, ap) + 1; std::cout << count << ": "; if (count <= 0) { return "unable to format message"; } std::string result = std::string(count, '\0'); if (vsnprintf(&result[0], count, fmt, ap) < 0) { return "error";} return result; }