C++ 如何将CAtlStringW与boost格式一起使用?
我试过这个:C++ 如何将CAtlStringW与boost格式一起使用?,c++,visual-studio-2010,boost-format,C++,Visual Studio 2010,Boost Format,我试过这个: #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
#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。
我尝试了一些变化,比如定义操作符Doh
我错过了“w”:
std::wostream& operator<<(std::wostream& os, const ATL::CAtlStringW& string)
{
return os << string.GetString();
}