【问题标题】:Cannot convert from wstring with Boost Format()无法使用 Boost Format() 从 wstring 转换
【发布时间】:2016-06-10 01:59:54
【问题描述】:

我有一个异常类定义如下:

class DeviceOpenException : public std::runtime_error {
public:
    DeviceOpenException(const std::string& message)
        : std::runtime_error("Device Open Exception: " + message) { };
}; 

我抛出异常如下:

throw DeviceOpenException(boost::str(boost::format("Cannot Open HID Device [Vendor ID = %1%] [Product ID = %2%] [Serial Number = %3%]") % vendorID %productID % serialNumber));

其中给former的参数如下:

(unsigned short vendorID, unsigned short productID, std::wstring serialNumber)

但是,这会导致以下编译错误:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion)

是我,还是 Boost 格式化程序不适用于 wstring 类型?

【问题讨论】:

    标签: c++ string boost wstring


    【解决方案1】:

    对宽字符串使用boost::wformat。请参阅文档here

    注意 typedef:

    typedef basic_format&lt;wchar_t &gt; wformat;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多