Typesafe printf-like formatting with boost::format
6
boost::format gives you the ablility to safely use printf like formatting as well as positional format specifiers ala .NET.
#include <boost/format.hpp>
#include <iostream>
using boost::format;
using namespace std;
int main(int argc, char* argv[]) {
unsigned int hexNum = 0xFFEEDDCC;
cout << format("Formatting a hex number: %08X") % hexNum << endl;
cout << format("Positional Specifiers: %3% %1% %2% %1%")
% 1 % 2 % 3 << endl;
return 0;
}
Formatting a hex number: 0xFFEEDDCC
Positional Specifiers: 3 1 2 1






There are currently no comments for this snippet.