// [src] https://github.com/apfeltee/cpp11-sprintf #include #include #include std::string fmt( const char *format ) { return format ? format : ""; } template std::string fmt( const char *format, const Type& value, Args... args) { std::stringstream strm; if( format ) { do { if(*format == '%') { strm << value; strm << fmt( format+1, args... ); return strm.str(); } strm << *format++; } while(*format); } //assert(!"too many args"); return strm.str(); } int main() { std::cout << fmt("Hello, %! It's %:% o'clock in %.", "doc", 12, 4, "funkytown") << std::endl; std::cout << fmt("") << std::endl; std::cout << fmt(0) << std::endl; }