Boost C++ Libraries: Ticket #6160: support for (istream >> array < char >) https://svn.boost.org/trac10/ticket/6160 <ol><li><code>array &lt; T &gt;</code> is a replacement for <code>T []</code> </li><li>the standard library provides the syntax <code>(istream &gt;&gt; char [])</code> and <code>(ostream &lt;&lt; char const [])</code> </li><li>Currently, <code>(istream &gt;&gt; array &lt; char &gt;)</code> does not mean anything </li><li>this functionality cannot be simulated even with <code>std:: copy_n &lt; istreambuf_iterator &gt;</code> without manual termination and much verbosity </li></ol><h2 class="section" id="Myimplementation">My implementation</h2> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;boost/array.hpp&gt; /* for ::boost:: array */</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/version.hpp&gt;</span><span class="cp"></span> <span class="cp">#if +BOOST_VERSION &lt;= 0313720</span> <span class="cp">#include</span> <span class="cpf">&lt;iomanip&gt; /* for ::std:: setw */</span><span class="cp"></span> <span class="k">namespace</span> <span class="n">boost</span> <span class="p">{</span> <span class="cm">/* helper classes to prevent ambiguity in matching array &lt; char &gt; */</span> <span class="k">namespace</span> <span class="n">detail_</span> <span class="p">{</span> <span class="cm">/* normally, other char for every character type is char */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_C</span> <span class="o">&gt;</span> <span class="k">class</span> <span class="nc">other_char</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="k">typedef</span> <span class="kt">char</span> <span class="n">type</span><span class="p">;</span> <span class="p">};</span> <span class="cm">/* but other_char is undefined for char */</span> <span class="k">template</span> <span class="o">&lt;&gt;</span> <span class="k">class</span> <span class="nc">other_char</span> <span class="o">&lt;</span> <span class="kt">char</span> <span class="o">&gt;</span> <span class="p">{};</span> <span class="cm">/* class same_stream fails for istream */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_S</span><span class="p">,</span> <span class="k">class</span> <span class="nc">P_C</span> <span class="o">=</span> <span class="k">typename</span> <span class="n">other_char</span> <span class="o">&lt;</span> <span class="k">typename</span> <span class="n">P_S</span><span class="o">::</span> <span class="n">char_type</span> <span class="o">&gt;::</span> <span class="n">type</span> <span class="o">&gt;</span> <span class="k">class</span> <span class="nc">same_stream</span> <span class="p">{</span> <span class="k">public</span><span class="o">:</span> <span class="k">typedef</span> <span class="n">P_S</span> <span class="n">stream</span><span class="p">;</span> <span class="p">};</span> <span class="p">}</span> <span class="cm">/* template input */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_C</span><span class="p">,</span> <span class="k">class</span> <span class="nc">P_T</span><span class="p">,</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="kt">size_t</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">static</span> <span class="kr">inline</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_istream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">&gt;&gt;</span> <span class="p">(</span><span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_istream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_s</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span> <span class="n">array</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_a</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">p_s</span> <span class="o">&gt;&gt;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">setw</span> <span class="p">(</span><span class="n">p_a</span><span class="p">.</span> <span class="n">static_size</span><span class="p">)</span> <span class="o">&gt;&gt;</span> <span class="n">p_a</span><span class="p">.</span> <span class="n">data</span> <span class="p">();</span> <span class="p">}</span> <span class="cm">/* character input, disabled for type char to avoid ambiguity */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_C</span><span class="p">,</span> <span class="k">class</span> <span class="nc">P_T</span><span class="p">,</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="kt">size_t</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">static</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">detail_</span><span class="o">::</span> <span class="n">same_stream</span> <span class="o">&lt;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_istream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&gt;::</span> <span class="n">stream</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">&gt;&gt;</span> <span class="p">(</span><span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_istream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_s</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span> <span class="n">array</span> <span class="o">&lt;</span> <span class="kt">char</span><span class="p">,</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_a</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">p_s</span> <span class="o">&gt;&gt;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">setw</span> <span class="p">(</span><span class="n">p_a</span><span class="p">.</span> <span class="n">static_size</span><span class="p">)</span> <span class="o">&gt;&gt;</span> <span class="n">p_a</span><span class="p">.</span> <span class="n">data</span> <span class="p">();</span> <span class="p">}</span> <span class="cm">/* template output */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_C</span><span class="p">,</span> <span class="k">class</span> <span class="nc">P_T</span><span class="p">,</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="kt">size_t</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">static</span> <span class="kr">inline</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_ostream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_ostream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_s</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span> <span class="n">array</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">const</span> <span class="o">&amp;</span><span class="n">p_a</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">p_s</span> <span class="o">&lt;&lt;</span> <span class="n">p_a</span><span class="p">.</span> <span class="n">begin</span> <span class="p">();</span> <span class="p">}</span> <span class="cm">/* character output, disabled for type char */</span> <span class="k">template</span> <span class="o">&lt;</span> <span class="k">class</span> <span class="nc">P_C</span><span class="p">,</span> <span class="k">class</span> <span class="nc">P_T</span><span class="p">,</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="kt">size_t</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">static</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">detail_</span><span class="o">::</span> <span class="n">same_stream</span> <span class="o">&lt;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_ostream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&gt;::</span> <span class="n">stream</span> <span class="o">&amp;</span><span class="k">operator</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">basic_ostream</span> <span class="o">&lt;</span> <span class="n">P_C</span><span class="p">,</span> <span class="n">P_T</span> <span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">p_s</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span> <span class="n">array</span> <span class="o">&lt;</span> <span class="kt">char</span><span class="p">,</span> <span class="n">P_N</span> <span class="o">&gt;</span> <span class="k">const</span> <span class="o">&amp;</span><span class="n">p_a</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">p_s</span> <span class="o">&lt;&lt;</span> <span class="n">p_a</span><span class="p">.</span> <span class="n">begin</span> <span class="p">();</span> <span class="p">}}</span> <span class="cp">#endif </span><span class="cm">/* BOOST_VERSION */</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;cstdlib&gt; /* for EXIT_SUCCESS */</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;cstdio&gt; /* for BUFSIZ */</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt; /* for ::std:: cin */</span><span class="cp"></span> <span class="kt">int</span> <span class="n">main</span> <span class="p">()</span> <span class="p">{</span> <span class="c1">// char (&amp;x) [+BOOST_VERSION] = 0;</span> <span class="cp">#ifdef ARRAY_IN_NATIVE</span> <span class="cm">/* native code */</span> <span class="kt">char</span> <span class="n">t</span> <span class="p">[</span><span class="o">+</span><span class="n">BUFSIZ</span><span class="p">];</span> <span class="k">return</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">setw</span> <span class="p">(</span><span class="o">+</span><span class="n">BUFSIZ</span><span class="p">)</span> <span class="o">&gt;&gt;</span> <span class="n">t</span> <span class="o">&amp;&amp;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">t</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;\n&#39;</span><span class="o">?</span> <span class="o">+</span><span class="nl">EXIT_SUCCESS</span><span class="p">:</span> <span class="o">+</span><span class="n">EXIT_FAILURE</span><span class="p">;</span> <span class="cp">#else </span><span class="cm">/* ARRAY_IN_NATIVE */</span><span class="cp"></span> <span class="cm">/* equivalent Boost code */</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span> <span class="n">array</span> <span class="o">&lt;</span> <span class="kt">char</span><span class="p">,</span> <span class="o">+</span><span class="n">BUFSIZ</span> <span class="o">&gt;</span> <span class="n">t</span><span class="p">;</span> <span class="cm">/* check that character input compiles for wchar_t */</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="k">sizeof</span> <span class="p">(</span><span class="n">std</span><span class="o">::</span> <span class="n">wcin</span> <span class="o">&gt;&gt;</span> <span class="n">t</span><span class="p">);</span> <span class="k">return</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="n">t</span> <span class="o">&amp;&amp;</span> <span class="o">::</span><span class="n">std</span><span class="o">::</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">t</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;\n&#39;</span><span class="o">?</span> <span class="o">+</span><span class="nl">EXIT_SUCCESS</span><span class="p">:</span> <span class="o">+</span><span class="n">EXIT_FAILURE</span><span class="p">;</span> <span class="cp">#endif </span><span class="cm">/* ARRAY_IN_NATIVE */</span><span class="cp"></span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6160 Trac 1.4.3 Sebastian Redl Tue, 22 Nov 2011 10:05:14 GMT <link>https://svn.boost.org/trac10/ticket/6160#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:1</guid> <description> <blockquote class="citation"> <p> the standard library provides the syntax (istream &gt;&gt; char []) and (ostream &lt;&lt; char const []) </p> </blockquote> <p> No, it provides istream &gt;&gt; char* and ostream &lt;&lt; char const*. As such, you can quite easily use the c_array() and data() members to get pointers to the data: istream &gt;&gt; ar.c_array() and ostream &lt;&lt; ar.data(). </p> </description> <category>Ticket</category> </item> <item> <author>ne01026@…</author> <pubDate>Tue, 22 Nov 2011 10:19:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:1" title="Comment 1">cornedbee</a>: </p> <blockquote class="citation"> <blockquote class="citation"> <p> the standard library provides the syntax (istream &gt;&gt; char []) and (ostream &lt;&lt; char const []) </p> </blockquote> <p> No, it provides istream &gt;&gt; char* and ostream &lt;&lt; char const*. As such, you can quite easily use the c_array() and data() members to get pointers to the data: istream &gt;&gt; ar.c_array() and ostream &lt;&lt; ar.data(). </p> </blockquote> <p> The call <del><code>istream &gt;&gt; ar.c_array ()</code></del> invites buffer overflow and undefined behaviour. If it were that simple, I would not bother writing so many words here. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 28 Nov 2011 15:52:36 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/6160#comment:3 https://svn.boost.org/trac10/ticket/6160#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I don't see the difference between: <code>istream &gt;&gt; char *</code> , <code>istream &gt;&gt; char []</code> and <code>istream &gt;&gt; boost::array&lt;char&gt;</code> in terms of buffer overflow prevention. </p> <p> It seems to me that in each case, it is the responsibility of the person providing the input to make sure that the input fits into the provided buffer. </p> <p> Am I missing something here? </p> Ticket ne01026@… Mon, 28 Nov 2011 16:07:04 GMT <link>https://svn.boost.org/trac10/ticket/6160#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:4</guid> <description> <p> <code>char []</code> has unknown length, <code>array &lt; char &gt;</code> has known length, therefore <code>&gt;&gt; array</code> is safer than <code>&gt;&gt; char []</code>, and my code, attached, q.v., uses this information to prevent buffer overflow. </p> </description> <category>Ticket</category> </item> <item> <author>ne01026@…</author> <pubDate>Mon, 28 Nov 2011 16:10:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:3" title="Comment 3">marshall</a>: </p> <blockquote class="citation"> <p> It seems to me that in each case, it is the responsibility of the person providing the input to make sure that the input fits into the provided buffer. </p> </blockquote> <p> This is not possible for general streams, unless your machine happens to be clairvoyant. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 28 Nov 2011 16:15:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:4" title="Comment 4">ne01026@…</a>: </p> <blockquote class="citation"> <p> <code>char []</code> has unknown length, <code>array &lt; char &gt;</code> has known length, therefore <code>&gt;&gt; array</code> is safer than <code>&gt;&gt; char []</code>, and my code, attached, q.v., uses this information to prevent buffer overflow. </p> </blockquote> <p> <code>char []</code> has known length - sizeof is your friend here. </p> <p> I see where your code is using the length to prevent a buffer overflow - but doing that at every stream extraction is error-prone, at best. It seems to me that (famous last words) that if this were to be implemented, it should never overflow the bounds of the array. </p> <p> Do you know if this was considered for std::array? </p> </description> <category>Ticket</category> </item> <item> <author>ne01026@…</author> <pubDate>Mon, 28 Nov 2011 16:43:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:6" title="Comment 6">marshall</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:4" title="Comment 4">ne01026@…</a>: </p> <blockquote class="citation"> <p> <code>char []</code> has unknown length, <code>array &lt; char &gt;</code> has known length, therefore <code>&gt;&gt; array</code> is safer than <code>&gt;&gt; char []</code>, and my code, attached, q.v., uses this information to prevent buffer overflow. </p> </blockquote> <p> <code>char []</code> has known length - sizeof is your friend here. </p> </blockquote> <p> <code>sizeof (char [])</code> is undefined. </p> <blockquote class="citation"> <p> I see where your code is using the length to prevent a buffer overflow - but doing that at every stream extraction is error-prone, at best. It seems to me that (famous last words) that if this were to be implemented, it should never overflow the bounds of the array. </p> </blockquote> <p> The extraction operator will not extract more characters than the array length, minus one, so where is the error? </p> <blockquote class="citation"> <p> Do you know if this was considered for std::array? </p> </blockquote> <p> I do not know; however, given that std takes from boost and not the other way round, I decided to put it here first. At least, the thing seems obvious and straighforward to me. The standard library has special semantics for (native) character arrays, and so should we. </p> <p> I tried to discuss the matter at #boost and I was told to file an enhancement, so here it is. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 28 Nov 2011 17:01:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:8</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:7" title="Comment 7">ne01026@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:6" title="Comment 6">marshall</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:4" title="Comment 4">ne01026@…</a>: </p> <blockquote class="citation"> <p> <code>char []</code> has unknown length, <code>array &lt; char &gt;</code> has known length, therefore <code>&gt;&gt; array</code> is safer than <code>&gt;&gt; char []</code>, and my code, attached, q.v., uses this information to prevent buffer overflow. </p> </blockquote> <p> <code>char []</code> has known length - sizeof is your friend here. </p> </blockquote> <p> <code>sizeof (char [])</code> is undefined. </p> </blockquote> <p> Sorry - I was imprecise: char [N] has size N for all N &gt; 0 </p> <blockquote class="citation"> <blockquote class="citation"> <p> Do you know if this was considered for std::array? </p> </blockquote> <p> I do not know; however, given that std takes from boost and not the other way round, I decided to put it here first. At least, the thing seems obvious and straighforward to me. The standard library has special semantics for (native) character arrays, and so should we. </p> <p> I tried to discuss the matter at #boost and I was told to file an enhancement, so here it is. </p> </blockquote> <p> And I'm glad that you did - and now we are discussing it. </p> <p> BTW - if this were to become part of boost, it would be more complicated. You should be able to extract from std::wcin to a boost::array&lt;wchar_t&gt;, for example. </p> </description> <category>Ticket</category> </item> <item> <author>ne01026@…</author> <pubDate>Mon, 28 Nov 2011 17:08:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:8" title="Comment 8">marshall</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:7" title="Comment 7">ne01026@…</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:6" title="Comment 6">marshall</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6160#comment:4" title="Comment 4">ne01026@…</a>: </p> <blockquote class="citation"> <p> <code>char []</code> has unknown length, <code>array &lt; char &gt;</code> has known length, therefore <code>&gt;&gt; array</code> is safer than <code>&gt;&gt; char []</code>, and my code, attached, q.v., uses this information to prevent buffer overflow. </p> </blockquote> <p> <code>char []</code> has known length - sizeof is your friend here. </p> </blockquote> <p> <code>sizeof (char [])</code> is undefined. </p> </blockquote> <p> Sorry - I was imprecise: char [N] has size N for all N &gt; 0 </p> </blockquote> <p> Unfortunately, the standard library does not provide <code>istream &gt;&gt; char (&amp;) [N]</code> as some older compilers are unable to match against such a template, so the best we can do is to define this thing for array. </p> <blockquote class="citation"> <p> BTW - if this were to become part of boost, it would be more complicated. You should be able to extract from std::wcin to a boost::array&lt;wchar_t&gt;, for example. </p> </blockquote> <p> I already do, that is why the code is so ugly :-( </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 28 Nov 2011 17:17:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6160#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6160#comment:10</guid> <description> <blockquote class="citation"> <blockquote class="citation"> <p> BTW - if this were to become part of boost, it would be more complicated. You should be able to extract from std::wcin to a boost::array&lt;wchar_t&gt;, for example. </p> </blockquote> <p> I already do, that is why the code is so ugly :-( </p> </blockquote> <p> I apologize. I clearly did not read your code closely enough. </p> </description> <category>Ticket</category> </item> </channel> </rss>