title: HowTo compare std::wstring & char*?
body: <p>What I have:</p>
  
  <ul>
  <li>[wstr1] 1 <strong>std::wstring</strong> value (e.g. "(GMT+04:30) Kabul")</li>
  <li>[str2] 1 <strong>char*</strong> filled with the same data as std::wstring (with the same text)</li>
  </ul>
  
  <p>I'm simply trying to compare this two value - but the following code doesn't appear to work. KMP.</p>
  
  <p>Here is the converter from char* to std::wstring, </p>
  
  <pre><code>std::wstring TimeZone::TimeZone::char2ws(const char* src)
  {
      /* Convert to a wchar_t*
       * http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx
       */
  
      // Convert to a wchar_t*
      size_t origsize = strlen(src) + 1;
      const size_t newsize = 512;
      size_t convertedChars = 0;
      wchar_t wcstring[newsize];
      mbstowcs_s(&amp;convertedChars, wcstring, origsize, src, _TRUNCATE);
  
      return wcstring;
  }
  </code></pre>
  
  <p>after that I made simple compare with</p>
  
  <pre><code>// wstr1 is std::wstring, with "(GMT+04:30) Kabul" string
  // wstr2 = char2ws(str2), 
  return (wstr1 == wstr2);
  </code></pre>
  
  <p>And no luck. String in VSVC2008 IDE debugger are visually equal.</p>
  
  <p><strong>Question</strong>: why do compare method gives me <em>false</em> always?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p><strong>Solution</strong>: great thanks to <a href="https://stackoverflow.com/users/373025/alexandre-c">Alexandre C.</a></p>
  
  <pre><code>bool weirdEquals(const std::wstring&amp; str, char const* c)
  {
      std::string c_str(c);
      if (str.size() &lt; c_str.size())
      {
          return false;
      }
      return std::equal(c_str.begin(), c_str.end(), str.begin());
  }
  </code></pre>
  
  <p>PS. I made some changes.</p>