我试过了:
#include <iostream>
#include <boost\format.hpp>
#include <atlstr.h>
std::ostream& operator<<(std::ostream& os, const ATL::CAtlStringW& string)
{
return os << string.GetString();
}
int _tmain(int argc, _TCHAR* argv[])
{
CAtlStringW world = L"world";
boost::wformat formatter(L"hello %s");
formatter % world;
std::wstring formatted = formatter.str();
return 0;
}
并格式化为“hello 004B54D8”,但我希望它是“hello world”。 我尝试了一些变体,比如定义运算符&lt;&lt;在命名空间内。我错过了什么?运算符&lt;&lt;似乎没有被召唤。
感谢。
boost格式文档提供了以下用于格式化自定义类型的示例:http://www.boost.org/doc/libs/1_49_0/libs/format/example/sample_userType.cpp
答案 0 :(得分:0)
卫生署。
我错过了'w's:
std::wostream& operator<<(std::wostream& os, const ATL::CAtlStringW& string)
{
return os << string.GetString();
}