ChartDirector 7.1 (C++ Edition)

WCHARtoUTF8


ChartDirector always uses UTF8 strings of type "char *" in its API. In C++, a common data type for international characters is the wide character type "wchar_t". The WCHARtoUTF8 can be used to convert a wide string to a UTF8 string. A related utility class UTF8toWCHAR performs the reverse conversion.

WCHARtoUTF8 has a constructor that accepts a wide character pointer "wchar_t *", and an implicit type casting operator to cast to "const char *". Thus it can be used like a function that accepts a wide string as input and returns a UTF8 string as output. Note that the memory required for the output is from the WCHARtoUTF8 object, so it must be used before the object is destroyed.

A typical usage is like:

obj->functionRequiringUTF8(WCHARtoUTF8(a_wchar_t_string));

In the above, the WCHARtoUTF8 object is destroyed after the function returns, so the converted UTF8 string is valid for the lifetime of the function call.

MethodInheritedDescription
WCHARtoUTF8(Self)Constructs a WCHARtoUTF8 object.
const_char_ptr(Self)Operator for implicit casting to const char *.