title: c++ convert from UTF-8 to wstring using iconv
body: <p>I have a c++ linux application which runs the following:</p>
  
  <pre><code>int main()
  {
    using namespace std;
    char str[] = "¡Hola!";
  
    wchar_t wstr[50];
  
    size_t rc;
  
    memset(wstr, 0, sizeof(wstr));
  
    rc = mbstowcs(wstr, str, 50);
  
    cout &lt;&lt; "mbstowcs results: ";
    cout &lt;&lt; "rc = " &lt;&lt; rc &lt;&lt; endl;
    cout &lt;&lt; "str:" &lt;&lt; str  &lt;&lt; endl;
    wcout &lt;&lt; L"wstr:" &lt;&lt; wstr  &lt;&lt; endl;
    setlocale(LC_CTYPE,"");
    iconv_t cd = iconv_open("WCHAR_T", "UTF-8");
    cout &lt;&lt; "iconv_open errno = "&lt;&lt; errno &lt;&lt; endl;
  
    char *s = str;
    char *t = (char *)wstr;
    size_t s1 = strlen(str);
    size_t s2 = 50;
  
    rc = iconv(cd, &amp;s, &amp;s1, &amp;t, &amp;s2);
  
    cout &lt;&lt; "iconv results: ";
    cout &lt;&lt; "rc = " &lt;&lt; rc &lt;&lt; endl;
    cout &lt;&lt; "str:" &lt;&lt; str  &lt;&lt; endl;
    wcout &lt;&lt; L"wstr:" &lt;&lt; wstr  &lt;&lt; endl;
  
  }
  </code></pre>
  
  <p>I want to convert a UTF-8 char vector to wstring, but the above code return this result:</p>
  
  <pre><code> mbstowcs results: rc = 18446744073709551615
      str:¡Hola!
      wstr:
      iconv_open errno = 2
      iconv results: rc = 0
      str:¡Hola!
      wstr:�Hola!
  </code></pre>
  
  <p>iconv result convert the first char to another char.</p>
  
  <p>Note: if I replace the WCHAR_T in UCS-4 -INTERNAL the wstr contains nothing.</p>
  
  <p>any help?</p>
  
  <p>thanks!</p>