<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 183: I/O stream manipulators don't work for wide character streams</title>
<meta property="og:title" content="Issue 183: I/O stream manipulators don't work for wide character streams">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue183.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#CD1">CD1</a> status.</em></p>
<h3 id="183"><a href="lwg-defects.html#183">183</a>. I/O stream manipulators don't work for wide character streams</h3>
<p><b>Section:</b> 31.7.7 <a href="https://wg21.link/std.manip">[std.manip]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Andy Sawyer <b>Opened:</b> 1999-07-07 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#std.manip">active issues</a> in [std.manip].</p>
<p><b>View all other</b> <a href="lwg-index.html#std.manip">issues</a> in [std.manip].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>31.7.7 <a href="https://wg21.link/std.manip">[std.manip]</a> paragraph 3 says (clause numbering added for
exposition):</p>
<blockquote>
<p>Returns: An object s of unspecified type such that if [1] out is an (instance
of) basic_ostream then the expression out&lt;&lt;s behaves as if f(s) were
called, and if [2] in is an (instance of) basic_istream then the expression
in&gt;&gt;s behaves as if f(s) were called. Where f can be defined as: ios_base&amp;
f(ios_base&amp; str, ios_base::fmtflags mask) { // reset specified flags
str.setf(ios_base::fmtflags(0), mask); return str; } [3] The expression
out&lt;&lt;s has type ostream&amp; and value out. [4] The expression in&gt;&gt;s
has type istream&amp; and value in.</p>
</blockquote>
<p>Given the definitions [1] and [2] for out and in, surely [3] should read:
&quot;The expression out &lt;&lt; s has type basic_ostream&amp; ...&quot; and
[4] should read: &quot;The expression in &gt;&gt; s has type basic_istream&amp;
...&quot;</p>
<p>If the wording in the standard is correct, I can see no way of implementing
any of the manipulators so that they will work with wide character streams.</p>
<p>e.g. wcout &lt;&lt; setbase( 16 );</p>
<p>Must have value 'wcout' (which makes sense) and type 'ostream&amp;' (which
doesn't).</p>
<p>The same &quot;cut'n'paste&quot; type also seems to occur in Paras 4,5,7 and
8. In addition, Para 6 [setfill] has a similar error, but relates only to
ostreams.</p>
<p>I'd be happier if there was a better way of saying this, to make it clear
that the value of the expression is &quot;the same specialization of
basic_ostream as out&quot;&amp;</p>


<p id="res-183"><b>Proposed resolution:</b></p>
<p>Replace section 31.7.7 <a href="https://wg21.link/std.manip">[std.manip]</a> except paragraph 1 with the
following:</p>
<blockquote>
<p>2- The type designated smanip in each of the following function descriptions is implementation-specified and may be different for each
function.<br/>
<br/>
<code>smanip resetiosflags(ios_base::fmtflags mask);</code><br/>
<br/>
-3- Returns: An object s of unspecified type such that if out is an instance of basic_ostream&lt;charT,traits&gt; then the expression out&lt;&lt;s behaves
as if f(s, mask) were called, or if in is an instance of basic_istream&lt;charT,traits&gt; then the expression in&gt;&gt;s behaves as if
f(s, mask) were called. The function f can be defined as:*<br/>
<br/>
[Footnote: The expression cin &gt;&gt; resetiosflags(ios_base::skipws) clears ios_base::skipws in the format flags stored in the
basic_istream&lt;charT,traits&gt; object cin (the same as cin &gt;&gt; noskipws), and the expression cout &lt;&lt; resetiosflags(ios_base::showbase) clears
ios_base::showbase in the format flags stored in the basic_ostream&lt;charT,traits&gt; object cout (the same as cout &lt;&lt;
noshowbase). --- end footnote]<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp; <code>ios_base&amp; f(ios_base&amp; str, ios_base::fmtflags mask)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  reset specified flags<br/>
&nbsp;&nbsp; str.setf(ios_base::fmtflags(0), mask);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type basic_ostream&lt;charT,traits&gt;&amp; and value out.
The expression in&gt;&gt;s has type basic_istream&lt;charT,traits&gt;&amp; and value in.<br/>
<br/>
&nbsp;<code>smanip setiosflags(ios_base::fmtflags mask);</code><br/>
<br/>
-4- Returns: An object s of unspecified type such that if out is an instance of basic_ostream&lt;charT,traits&gt; then the expression out&lt;&lt;s behaves
as if f(s, mask) were called, or if in is an instance of basic_istream&lt;charT,traits&gt; then the expression in&gt;&gt;s behaves as if f(s,
mask) were called. The function f can be defined as:<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp; <code>ios_base&amp; f(ios_base&amp; str, ios_base::fmtflags mask)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  set specified flags<br/>
&nbsp;&nbsp; str.setf(mask);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type basic_ostream&lt;charT,traits&gt;&amp; and value out.
The expression in&gt;&gt;s has type basic_istream&lt;charT,traits&gt;&amp; and value in.<br/>
<br/>
<code>smanip setbase(int base);</code><br/>
<br/>
-5- Returns: An object s of unspecified type such that if out is an instance of basic_ostream&lt;charT,traits&gt; then the expression out&lt;&lt;s behaves
as if f(s, base) were called, or if in is an instance of basic_istream&lt;charT,traits&gt; then the expression in&gt;&gt;s behaves as if f(s,
base) were called. The function f can be defined as:<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp; <code>ios_base&amp; f(ios_base&amp; str, int base)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  set  basefield<br/>
&nbsp;&nbsp; str.setf(base ==  8 ? ios_base::oct :<br/>
&nbsp;&nbsp; base == 10 ? ios_base::dec :<br/>
&nbsp;&nbsp; base == 16 ? ios_base::hex :<br/>
&nbsp;&nbsp; ios_base::fmtflags(0), ios_base::basefield);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type basic_ostream&lt;charT,traits&gt;&amp; and value out.
The expression in&gt;&gt;s has type basic_istream&lt;charT,traits&gt;&amp; and value in.<br/>
<br/>
<code>smanip setfill(char_type c);<br/>
</code><br/>
-6- Returns: An object s of unspecified type such that if out is (or is derived from) basic_ostream&lt;charT,traits&gt; and c has type charT then the
expression out&lt;&lt;s behaves as if f(s, c) were called. The function f can be
defined as:<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>template&lt;class charT, class traits&gt;<br/>
&nbsp;&nbsp; basic_ios&lt;charT,traits&gt;&amp; f(basic_ios&lt;charT,traits&gt;&amp; str, charT c)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  set fill character<br/>
&nbsp;&nbsp; str.fill(c);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type basic_ostream&lt;charT,traits&gt;&amp; and value out.<br/>
<br/>
<code>smanip setprecision(int n);</code><br/>
<br/>
-7- Returns: An object s of unspecified type such that if out is an instance of basic_ostream&lt;charT,traits&gt; then the expression out&lt;&lt;s behaves
as if f(s, n) were called, or if in is an instance of basic_istream&lt;charT,traits&gt; then the expression in&gt;&gt;s behaves as if f(s, n)
were called. The function f can be defined as:<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>ios_base&amp; f(ios_base&amp; str, int n)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  set precision<br/>
&nbsp;&nbsp; str.precision(n);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type basic_ostream&lt;charT,traits&gt;&amp; and value out.
The expression in&gt;&gt;s has type basic_istream&lt;charT,traits&gt;&amp; and value in<br/>
.<br/>
<code>smanip setw(int n);<br/>
</code><br/>
-8- Returns: An object s of unspecified type such that if out is an instance of basic_ostream&lt;charT,traits&gt; then the expression out&lt;&lt;s behaves
as if f(s, n) were called, or if in is an instance of basic_istream&lt;charT,traits&gt; then the expression in&gt;&gt;s behaves as if f(s, n)
were called. The function f can be defined as:<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <code>ios_base&amp; f(ios_base&amp; str, int n)<br/>
&nbsp;&nbsp; {<br/>
&nbsp;&nbsp; //  set width<br/>
&nbsp;&nbsp; str.width(n);<br/>
&nbsp;&nbsp; return str;<br/>
&nbsp;&nbsp; }<br/>
</code><br/>
The expression out&lt;&lt;s has type
basic_ostream&lt;charT,traits&gt;&amp; and value out.  The expression
in&gt;&gt;s has type basic_istream&lt;charT,traits&gt;&amp; and value
in.
</p>
</blockquote>

<p><i>[Kona: Andy Sawyer and Beman Dawes will work to improve the wording of
the proposed resolution.]</i></p>


<p><i>[Tokyo - The LWG noted that issue <a href="lwg-closed.html#216" title="setbase manipulator description flawed (Status: Dup)">216</a><sup><a href="https://cplusplus.github.io/LWG/issue216" title="Latest snapshot">(i)</a></sup> involves
the same paragraphs.]</i></p>


<p><i>[Post-Tokyo: The issues list maintainer combined the proposed
resolution of this issue with the proposed resolution for issue <a href="lwg-closed.html#216" title="setbase manipulator description flawed (Status: Dup)">216</a><sup><a href="https://cplusplus.github.io/LWG/issue216" title="Latest snapshot">(i)</a></sup> as they both involved the same paragraphs, and were so
intertwined that dealing with them separately appear fraught with
error.  The full text was supplied by Bill Plauger; it was cross
checked against changes supplied by Andy Sawyer. It should be further
checked by the LWG.]</i></p>






</body>
</html>
