Boost logo

Boost :

Subject: [boost] [format] convenient format wrapper
From: Alexey Klimkin (klimkin_at_[hidden])
Date: 2013-09-06 16:11:24

I found this boost::format wrapper to be very convenient as replacement of
sprintf. Can something like that be a part of the library?

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

using namespace std;
using namespace boost;

my_format(format& fmter)
  return fmter;

template <typename T, typename... Args> format&
my_format(format& fmter, T value, Args... args)
  fmter % value;
  return my_format(fmter, args...);

my_format(string fmt)
  format fmter(fmt);
  return my_format(fmter).str();

template <typename... Args> string
my_format(string fmt, Args... args)
  format fmter(fmt);
  return my_format(fmter, args...).str();

  cout << my_format("%s %.6f", "pi", 3.14159) << endl;
  return 0;


Boost list run by bdawes at, gregod at, cpdaniel at, john at