The input data for iconv
is always an opaque byte stream. When reading UTF-16, iconv
expects the input data to consist of two-byte code units. Therefore, if you want to provide hard-coded input data, you need to use a two-byte wide integral type.
In C++11 and C11 this should be char16_t
, but you can also use uint16_t
:
uint16_t data[] = { 0x68, 0x69, 0 };
char const * p = (char const *)data;
To be pedantic, there's nothing in general that says that uint16_t
has two bytes. However, iconv
is a Posix library, and Posix mandates that CHAR_BIT == 8
, so it is true on Posix.
(Also note that the way you spell a literal value has nothing to do with the width of the type which you initialize with that value, so there's no difference between 0x68
, 0x0068
, or 0x00068
. What's much more interesting are the new Unicode character literals \u
and \U
, but that's a whole different story.)