【问题标题】:How do you use a CAtlStringW with boost format?你如何使用带有 boost 格式的 CAtlStringW?
【发布时间】:2012-04-17 10:23:51
【问题描述】:

我试过这个:

#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”。 我尝试了一些变体,例如在命名空间中定义 operator

谢谢。

boost 格式文档提供了以下用于格式化自定义类型的示例:http://www.boost.org/doc/libs/1_49_0/libs/format/example/sample_userType.cpp

【问题讨论】:

    标签: c++ visual-studio-2010 boost-format


    【解决方案1】:

    哦。

    我错过了'w's:

    std::wostream& operator<<(std::wostream& os, const ATL::CAtlStringW& string)
    {
        return os << string.GetString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2021-08-04
      • 1970-01-01
      • 2020-03-09
      相关资源
      最近更新 更多