Using std::copy to copy wide strings on Windows
<p>Let's say I have a wide string like this<br></p>

<pre><code>std::wstring s(L"Stack Over Flow");
</code></pre>

<p>that I want to copy into a vector of wide characters <code>std::vector&lt;wchar_t&gt;</code> (of a null terminated string ) using <code>std::copy</code> <br>
Both the following approaches seem to work <br>
First<br></p>

<pre><code>std::vector&lt;wchar_t&gt; c( s.size() + 1 );
std::copy(s.c_str(), s.c_str() + s.length() + 1, c.begin());
wprintf( L"%s\n",&amp;c[0] );
</code></pre>

<p>Second<br></p>

<pre><code>std::vector&lt;wchar_t&gt; d( s.size() + sizeof(wchar_t));
std::copy(s.c_str(), s.c_str() + s.length() + sizeof(wchar_t), d.begin());
wprintf( L"%s\n",&amp;d[0] );
</code></pre>

<p>But I am thinking the first should fail because I am not allocating the correct size for the ending null character. What did I miss?<br>
<strong>Edit</strong><br>
No, I don't want to to this<br></p>

<pre><code>std::vector&lt;wchar_t&gt; c(s.begin(), s.end()); &lt;br&gt;
</code></pre>

<p>because I am resizing an existing buffer <br>
<strong>Edit</strong><br>
By changing the use case (print using the C like API ) I can see that the second version is probably the correct one.<br>
First prints <code>Stack Over Flow????????</code><br>
Second prints <code>Stack Over Flow</code>  as expected</p>
