: explicitly pass the system locale ID for system_category messages by fsb4000 · Pull Request #2669 · microsoft/STL (original) (raw)

type main.cpp #include #include #include

#include <Windows.h>

int main() { setlocale(LC_ALL, ""); auto file_handle(CreateFile( L"D:\non_exist_file.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); if (file_handle == INVALID_HANDLE_VALUE) { const auto error_code = GetLastError(); std::string errmsg = std::system_category().message(error_code); // Sometimes the string only contains "???" std::cout << errmsg << '\n'; } }

If we have different “user language id” and “system language id” (this is how we can reach it: #2451 (comment)) FormatMessageA can choose “user language id” instead of “system language id” if we pass 0.