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++?
Sample input:
123
pad to 10 characters.
Sample output:
123
(7 spaces in front of 123)
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++?
Sample input:
123
pad to 10 characters.
Sample output:
123
(7 spaces in front of 123)
Create a new string of 10 spaces, and work backwards in both string.
There's a nice and simple way :)
The easiest way I can think of would be with a stringstream:
foo
should now be padded.