I am trying to write table to stdout with numerical data. I would like to format so that numbers are aligned like:
1234 23
312 2314
12 123
I know that max length of the number is 6 chars, is there a smart way to know how many spaces needs to be output before number so it looks exactly like this?
printfmay be the quickest solution:Prints:
Something similar can be achieved with an arduous and verbose sequence of iostream commands; someone else will surely post such an answer should you prefer the “pure C++” taste of that.
Update: Actually, the iostreams version isn’t that much more terrible. (As long as you don’t want scientific float formatting or hex output, that is.) Here it goes: