Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Solution from: <a href="http://forums.devshed.com/c-programming-42/wstring-to-string-444006.html" rel="noreferrer">http://forums.devshed.com/c-programming-42/wstring-to-string-444006.html</a> </p> <pre><code>std::wstring wide( L"Wide" ); std::string str( wide.begin(), wide.end() ); // Will print no problemo! std::cout &lt;&lt; str &lt;&lt; std::endl; </code></pre> <hr> <p><strong>Beware</strong> that there is <em>no</em> character set conversion going on here at all. What this does is simply to assign each iterated <code>wchar_t</code> to a <code>char</code> - a truncating conversion. It uses the <a href="http://en.cppreference.com/w/cpp/string/basic_string/basic_string" rel="noreferrer">std::string c'tor</a>: </p> <pre><code>template&lt; class InputIt &gt; basic_string( InputIt first, InputIt last, const Allocator&amp; alloc = Allocator() ); </code></pre> <p>As stated in comments:</p> <blockquote> <p>values 0-127 are identical in virtually every encoding, so truncating values that are all less than 127 results in the same text. Put in a chinese character and you'll see the failure.</p> </blockquote> <p>-</p> <blockquote> <p>the values 128-255 of windows codepage 1252 (the Windows English default) and the values 128-255 of unicode are mostly the same, so if that's teh codepage you're using most of those characters should be truncated to the correct values. (I totally expected á and õ to work, I know our code at work relies on this for é, which I will soon fix)</p> </blockquote> <p>And note that code points in the range <code>0x80 - 0x9F</code> in <a href="https://en.wikipedia.org/wiki/Windows-1252" rel="noreferrer">Win1252</a> will <em>not</em> work. This includes <code>€</code>, <code>œ</code>, <code>ž</code>, <code>Ÿ</code>, ...</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. 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.
 

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