C++11 Equivalent to Boost.Format

Chris Redford picture Chris Redford · May 1, 2014 · Viewed 14k times · Source

Anything like Boost.Format in the C++11 standard? I've been able to avoid using Boost with a better C++11 option for every other need I've had.

For that matter, Boost.Format doesn't hold a candle to the syntax of Python format(). Something like that would be even better.

Answer

vitaut picture vitaut · Oct 8, 2014

C++11, 14 and 17 don't provide anything like that.

However, C++20 provides std::format which is similar in spirit to Boost Format but with the design permitting more efficient implementation. The {fmt} library is an implementation of this formatting facility and it only requires C++11:

std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");

Disclaimer: I'm the author of {fmt} and C++20 std::format