[英]boost::format and wchar_t
I am trying to format a string using boost: 我正在尝试使用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. 我得到的不是msg的内容,是以十六进制表示的msg的地址。
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: 注意:即使我认为它无关紧要,但我填写msg的方式是:
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. 和Visual Studio Watch正确显示msg的内容。
尝试使用boost::wformat
来处理wchar_t
字符串。
You can either use boost::wformat
as suggested by wilx. 您可以boost::wformat
建议使用boost::wformat
wformat。 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. 或者你可以改变你的格式字符串使用"%ls"
(其中l
是字母ELL,小L.)这会修改"%s"
期待宽字符的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.