C + + string format output mode

Time:2022-5-13

flyfish

Using the format of boost

Header file


#include <boost/format.hpp>

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

Equivalent to


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

Format similar to CString


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

The above C + + string formatted output method is all the content shared by Xiaobian. I hope it can give you a reference and support developeppaer.