Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like it's just an oversight in the standard specification.</p> <p><code>ios_base::precision</code> has two overloads, one that gets and one that sets the precision:</p> <pre><code>// returns current precision streamsize precision() const; // sets current precision and returns old value streamsize precision(streamsize prec) const; </code></pre> <p>So this code will not give you warnings:</p> <pre><code>#include &lt;iostream&gt; int main() { std::streamsize prec = std::cout.precision(); // gets std::cout.precision(prec); // sets } </code></pre> <p>However, the <code>setprecision()</code> function simply takes a plain old <code>int</code>:</p> <pre><code>unspecified-type setprecision(int n); </code></pre> <p>and returns an unspecified functor, which when consumed by a stream <code>str</code> has the effect of:</p> <pre><code>str.precision(n); </code></pre> <p>In your case, <code>streamsize</code> is not an <code>int</code> (and does not have to be), hence the warning. The standard should probably be changed so that <code>setprecision</code>'s parameter is not <code>int</code>, but <code>streamsize</code>.</p> <p>You can either just call <code>precison()</code> yourself, as above, or assume <code>int</code> is sufficient and cast.</p> <pre><code>#include &lt;iomanip&gt; #include &lt;iostream&gt; int main() { std::streamsize prec = std::cout.precision(); std::cout &lt;&lt; std::setprecision(static_cast&lt;int&gt;(prec)); } </code></pre> <p><em>Edit: <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#1148" rel="nofollow">Apparently it was submitted to be fixed and reached no concensus (closed as not-a-defect)</a>.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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