title: Center text in fixed-width field with stream manipulators in C++
body: <p>I am refactoring some legacy code which is using <code>printf</code> with longs strings (without any actual formatting) to print out plain text table headers which looks notionally like this:</p>
  
  <pre><code>|  Table   |  Column  | Header  |
  </code></pre>
  
  <p>which are currently being produced like this:</p>
  
  <pre><code>printf("|  Table   |  Column  | Header  |");
  </code></pre>
  
  <p>I would like to produce the above with code to the effect of<sup>1</sup>:</p>
  
  <pre><code>outputStream &lt;&lt; "|" &lt;&lt; std::setw(10) &lt;&lt; std::center &lt;&lt; "Table"
               &lt;&lt; "|" &lt;&lt; std::setw(10) &lt;&lt; std::center &lt;&lt; "Column"
               &lt;&lt; "|" &lt;&lt; std::setw(9) &lt;&lt; std::center &lt;&lt; "Header"
               &lt;&lt; "|" &lt;&lt; std::endl;
  </code></pre>
  
  <p>which does not compile because <code>&lt;iomanip&gt;</code> has the stream manipulators <code>std::left</code>, <code>std::right</code> and <code>std::internal</code>, but does not seem to have any <code>std::center</code>. Is there a clean way to do this already in standard C++ libraries, or will I have to manually compute the necessary spacing?</p>
  
  <hr>
  
  <p><sup>1</sup><sub>Even though this is more verbose than the C code, it will be less verbose in the long run because of the number of <code>printf</code> statements and the amount of infixed duplication in their strings. It will also be more extensible and maintainable.</sub></p>