Unable to convert between encodings using iconv
<p>I'm trying to convert a string in German language to UTF-16 using iconv, but in vain. Here's the code for it:</p>

<pre><code>#include &lt;iconv.h&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;errno.h&gt;

using namespace std;

const size_t BUF_SIZE=1024;

class IConv {
        iconv_t ic_;
public:
        IConv(const char* to, const char* from)
            : ic_(iconv_open(to,from))    { }
        ~IConv() { iconv_close(ic_); }

         bool convert(char* input, char* output, size_t&amp; out_size) {
            size_t inbufsize = strlen(input)+1;
            return iconv(ic_, &amp;input, &amp;inbufsize, &amp;output, &amp;out_size);
         }
};

int main(void)
{
    char str1[BUF_SIZE] = "tägelîch";
    char str2[BUF_SIZE] = "something else";
    IConv ic("en_US.UTF-8","UTF16LE");
    bool ret;

    cout &lt;&lt; str1 &lt;&lt; endl;
    size_t outsize = BUF_SIZE;  //you will need it
    ret = ic.convert(str1, str2, outsize);
    if (ret == false) {
        cout &lt;&lt; "iconv failed: " &lt;&lt; errno &lt;&lt; endl;
        return -1;
    }
    cout &lt;&lt; str2 &lt;&lt; endl;
}
</code></pre>

<p>Output:</p>

<pre><code>$ ./a.out
tägelîch
something else
</code></pre>

<p>If the from encoding type is changed to <code>ISO-8859-1</code>, the result is the same. </p>

<p>On the other hand, iconv utility works fine from the command prompt:</p>

<pre><code>$ echo "TägelîcH" | iconv -f "ISO-8859-1" -t UTF-16LE
T▒▒gel▒▒cH
</code></pre>

<p><code>iconv --list</code> shows that both <code>ISO-8859-1</code> and <code>UTF-16LE</code> are supported. What am I missing?</p>

<p>Is C++ in any way causing this behaviour?</p>

<p>Thanks!</p>