【问题标题】:Printing bools with boost::format as symbolic values?使用 boost::format 打印布尔值作为符号值?
【发布时间】:2012-12-04 11:53:25
【问题描述】:

如何以boost::format 作为符号值打印布尔值?

没有boost::io::group 可以做到这一点吗?似乎预先发送到流的标志会重新测试:

#include <iomanip>
#include <iostream>
#include <boost/format.hpp>

int main()
{
  std::cout
    << std::boolalpha
    << true << " "
    << boost::format("%1% %2%\n")
         % true
         % boost::io::group(std::boolalpha, true)
    ;
}

输出

true 1 true

【问题讨论】:

    标签: c++ boost boost-format


    【解决方案1】:

    你可以这样归档:

    #include <iomanip>
    #include <iostream>
    #include <boost/format.hpp>
    
    int main()
    {
      std::cout
        << std::boolalpha
        << true << " "
        << boost::format("%1$b %2%\n")
             % true
             % boost::io::group(std::boolalpha, true)
        ;
    }
    

    【讨论】:

      【解决方案2】:

      在我看来你不能。

      我查看了 Boost.Format 文档和代码,但什么也没看到。

      另一方面,the sample code 展示了如何为用户定义的类型编写格式化程序。你可以为“bool”写一个

      【讨论】:

      猜你喜欢
      • 2015-09-14
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2019-07-31
      • 2018-02-10
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多