Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>setw()</code> only affects the next insertion. That's just the way <code>setw()</code> behaves. The behavior of <code>setw()</code> is the same as <code>ios_base::width()</code>. I got my <code>setw()</code> information from <a href="http://www.cplusplus.com" rel="noreferrer">cplusplus.com</a>. </p> <p>You can find a full list of manipulators <a href="http://www.cplusplus.com/reference/iostream/manipulators/" rel="noreferrer">here</a>. From that link, all the stream flags should say set until changed by another manipulator. One note about the <code>left</code>, <code>right</code> and <code>internal</code> manipulators: They are like the other flags and <em>do</em> persist until changed. However, they only have an effect when the width of the stream is set, and the width must be set every line. So, for example</p> <pre><code>cout.width(6); cout &lt;&lt; right &lt;&lt; "a" &lt;&lt; endl; cout.width(6); cout &lt;&lt; "b" &lt;&lt; endl; cout.width(6); cout &lt;&lt; "c" &lt;&lt; endl; </code></pre> <p>would give you</p> <pre><code>&gt; a &gt; b &gt; c </code></pre> <p>but </p> <pre><code>cout.width(6); cout &lt;&lt; right &lt;&lt; "a" &lt;&lt; endl; cout &lt;&lt; "b" &lt;&lt; endl; cout &lt;&lt; "c" &lt;&lt; endl; </code></pre> <p>would give you</p> <pre><code>&gt; a &gt;b &gt;c </code></pre> <p>The Input and Output manipulators are not sticky and only occur once where they are used. The parametrized manipulators are each different, here's a brief description of each:</p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/setiosflags" rel="noreferrer"><code>setiosflags</code></a> lets you manually set flags, a list of which can be fount <a href="http://www.cplusplus.com/reference/iostream/ios_base/fmtflags/" rel="noreferrer">here</a>, so it is sticky. </p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/resetiosflags/" rel="noreferrer"><code>resetiosflags</code></a> behaves the similar to <a href="http://www.cplusplus.com/reference/iostream/manipulators/setiosflags" rel="noreferrer"><code>setiosflags</code></a> except it unsets the specified flags. </p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/setbase/" rel="noreferrer"><code>setbase</code></a> sets the base of integers inserted into the stream (so 17 in base 16 would be "11", and in base 2 would be "10001"). </p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/setfill/" rel="noreferrer"><code>setfill</code></a> sets the fill character to insert in the stream when <code>setw</code> is used. </p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/setprecision/" rel="noreferrer"><code>setprecision</code></a> sets the decimal precision to be used when inserting floating point values. </p> <p><a href="http://www.cplusplus.com/reference/iostream/manipulators/setw/" rel="noreferrer"><code>setw</code></a> makes only the next insertion the specified width by filling with the character specified in <a href="http://www.cplusplus.com/reference/iostream/manipulators/setfill/" rel="noreferrer"><code>setfill</code></a> </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