C++ string格式化输出

来源:互联网 发布:摩比神奇 知乎 编辑:程序博客网 时间:2024/06/05 09:22

C++ string格式化输出

flyfish

利用boost的format

头文件

#include <boost/format.hpp>
boost::format f = boost::format("%.2f %s %d") % 1.234 %"123" % 12;    std::string s = f.str();

等同于

boost::format f = boost::format("%.2f %s %d");    f % 1.234 %"123" % 12;    std::string s = f.str();

类似CString的格式化

CString t = L"123";    CString s;    s.Format(L"%.2f %s %d",  1.234, t, 12);
原创粉丝点击