Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The old <code>stdio</code> functionality is in C++ for compatibility (and partially because the original C++ (cfront) was just a pre-processor for C so they were available anyway).</p> <p>The newer I/O model found in C++ is a lot more flexible, allowing you to add types at will, which can be printed in a way defined by that type.</p> <p>In other words, in an object oriented way.</p> <p>Just like complex or rational numbers numbers (or address book entries or dictionary entries or any other non-basic type for that matter) should be self contained in a class that knows how to add, subtract or otherwise manipulate them separately from the base language, the printing of those objects should also be left to the class as well.</p> <p>If you're worried about the verbosity of the C++ way, there's nothing stopping you from adding a <code>fmt()</code> method, returning a string, to your own data types to get around that problem, something like:</p> <pre><code>std::cout &lt;&lt; name.fmt('left',15) // [Pax Diablo ] &lt;&lt; " " &lt;&lt; age.fmt(4) // [ 45] &lt;&lt; " " &lt;&lt; score.fmt(3,2) // [100.00] &lt;&lt; std::endl; </code></pre> <p>for sizes and/or justifications.</p> <p>It's more coding on your part within the class but it <em>is</em> an option if you're really adverse to the <code>setfill</code> and <code>setw</code> stuff.</p> <p>However, since you'll almost certainly have your formatting code in a function for each type of output (if you're smart), it'll be isolated in one area. I'd just suck it up and learn the C++ way of doing things.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload