(C++) boost::format
August 17, 2019 · View on GitHub
boost::format is the type-safe alternative of std::printf(see example below).
#include <cstdio> #include <iostream> #include <boost/format.hpp> int main() { //Correct std::printf("(x,y) = (%1+5d,%2+5d) \n",-1,2); std::cout << boost::format("(x,y) = (%1+5d,%2+5d) \n") % -1 % 2; //Incorrect std::printf("(x,y) = (%1+5d,%2+5d) \n",-1.5,2.5); std::cout << boost::format("(x,y) = (%1+5d,%2+5d) \n") % -1.5 % 2.5; }
Screen output:
(x,y) = ( -1, +2) (x,y) = ( -1, +2) (x,y) = ( +0,-1074266112) (x,y) = ( -1.5, +2.5)
External links