Last active
August 29, 2015 14:24
-
-
Save aeppert/b57cb541d0a290837bf2 to your computer and use it in GitHub Desktop.
Template for string conversion with padding and prefix facility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <limits> | |
using namespace std; | |
template <class T> std::string to_string(T t, ios_base & (*f)(ios_base&), std::string prefix = "", bool pad = true) | |
{ | |
std::ostringstream oss; | |
if(pad) { | |
oss.fill('0'); | |
oss.width(std::numeric_limits<T>::digits/4); | |
} | |
oss << f << t; | |
prefix += oss.str(); | |
return prefix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment