C++ minimum string width

c++, iostream

Solution

You can use `setw` manipulator to set the width of the output, like this:

cout << setw(10) << a << endl;

The `iomanip` header needs to be included in order for this to compile.

Problem

Suppose I have ``` string a = "foo"; ``` How can I print `a` to the console using `printf` that ensure a minimum width, say, 10?

Original source