wchar_t vs. char16_t

R

Rui Maciel

A said:
whats the difference?

Both are different integral types defined in the standard, the latter added
in C++x11. While wchar_t is intended to store information in a format that
depends on the locale, char16_t appears to have been defined with the
specific purpose of encoding information following the UTF-16 format (as
char32_t with the UTF-32 format).

So, in practical terms, the main difference is that by using char16_t and
char32_t you specifically know what format is being used to encode your text
strings, while with wchar_t you don't.


Rui Maciel
 
J

Joshua Maurice

wchar_t has implementation defined size. On most unix-like systems,
it's 32 bit. On windows, it's 16 bit. If you're trying to use C++
locales portably, then it might make sense to use wchar_t. However,
the C++ locales are largely non-portable, which makes use of wchar_t
largely non-portable.
Both are different integral types defined in the standard, the latter added
in C++x11.  While wchar_t is intended to store information in a format that
depends on the locale, char16_t appears to have been defined with the
specific purpose of encoding information following the UTF-16 format (as
char32_t with the UTF-32 format).  

So, in practical terms, the main difference is that by using char16_t and
char32_t you specifically know what format is being used to encode your text
strings, while with wchar_t you don't.

To be technical, you can put whatever kind of data you want into
char16_t. It does lend itself to storing UTF16, but it doesn't require
that you put UTF16 into char16_t.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top