C++ string format output

  • 2020-06-23 01:30:43
  • OfStack

flyfish

Use format of boost

The header file


#include <boost/format.hpp>

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

Is equivalent to


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

Similar to CString formatting


CString t = L"123";
  CString s;
  s.Format(L"%.2f %s %d", 1.234, t, 12);

Related articles: