【问题标题】:Which part of boost library enables cout to print wstring and how?boost 库的哪一部分使 cout 能够打印 wstring 以及如何打印?
【发布时间】:2017-07-12 02:23:01
【问题描述】:

最近刚开始使用boost库,发现在包含某个boost头文件(可能是filesystem.h)后,cout函数可以完美的在同一个程序中打印出string和wstring。而且,打印wstring时,内容是用引号引起来的。

我对目前的行为非常满意,并希望充分了解其背后的机制,以避免任何可能的误操作。

【问题讨论】:

    标签: c++ boost cout wstring


    【解决方案1】:

    boost::filesystem::path 有一个来自string_type 的隐式转换构造函数,定义为std::basic_string<value_type>value_type 的定义取决于环境。值得注意的是,wchar_t 在 Windows 上。这意味着在 Windows 上,string_typestd::basic_string<wchar_t>,也就是 std::wstring

    因此,您的 wstring 被隐式转换为 boost::filesystem::path,该 boost::filesystem::path 被重载以通过 operator<< 进行打印。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-14
      • 2019-08-01
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多