Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should convert the <code>char</code> string to a <code>wchar_t</code> string using <code>mbstowcs</code>, and then compare the resulting strings. Notice that <code>mbstowcs</code> works on <code>char *</code>/<code>wchar *</code>, so you'll probably need to do something like this:</p> <pre><code>std::wstring StringToWstring(const std::string &amp; source) { std::wstring target(source.size()+1, L' '); std::size_t newLength=std::mbstowcs(&amp;target[0], source.c_str(), target.size()); target.resize(newLength); return target; } </code></pre> <p>I'm not entirely sure that that usage of <code>&amp;target[0]</code> is entirely standard-conforming, if someone has a good answer to that please tell me in the comments. Also, there's an implicit assumption that the converted string won't be longer (in number of <code>wchar_t</code>s) than the number of <code>char</code>s of the original string - a logical assumption that still I'm not sure it's covered by the standard.</p> <p>On the other hand, it seems that there's no way to ask to <code>mbstowcs</code> the size of the needed buffer, so either you go this way, or go with (better done and better defined) code from Unicode libraries (be it Windows APIs or libraries like iconv).</p> <p>Still, keep in mind that comparing Unicode strings without using special functions is slippery ground, two equivalent strings may be evaluated different when compared bitwise.</p> <p>Long story short: this should work, and I think it's the maximum you can do with just the standard library, but it's a lot implementation-dependent in how Unicode is handled, and I wouldn't trust it a lot. In general, it's just better to stick with an encoding inside your application and avoid this kind of conversions unless absolutely necessary, and, if you are working with definite encodings, use APIs that are less implementation-dependent.</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.
 

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