문제

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.

도움이 되었습니까?

해결책

Try using boost::wformat to work with wchar_t strings.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top