I\'m using std::string and need to left pad them to a given width. What is the recommended way to do this in C++?
std::string
Sample input:
123
void padTo(std::string &str, const size_t num, const char paddingChar = ' ') { if(num > str.size()) str.insert(0, num - str.size(), paddingChar); } int main(int argc, char **argv) { std::string str = "abcd"; padTo(str, 10); return 0; }