boost::format and wchar_t
-
29-10-2019 - |
Question
I am trying to format a string using boost:
wchar_t *msg;
// fill msg
boost::format("Error: %s") % msg).str()
What I get instead of msg's content, is the address of msg in hex.
No success with things like these:
boost::format("Error: %s") % new std::wstring(msg)
boost::format("Error: %1%") % msg
Note: Even though I think it's irrelevant, but the way that I fill msg is:
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | 40, NULL, GetLastError(), MAKELANGID(0, SUBLANG_ENGLISH_US), (LPTSTR) &msg, 512, NULL);
and Visual Studio Watch displays the content of msg correctly.
Solution
Try using boost::wformat
to work with wchar_t
strings.
OTHER TIPS
You can either use boost::wformat
as suggested by wilx. Or you can change your format string to use "%ls"
(where the l
is the letter ell, small L.) This modifies the "%s"
to expect wide character strings.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow