Size of wchar_t for unicode encoding

12,451

Solution 1

You won't be able to do it with std::wstring on many platforms because it will have 16 bit elements.

Instead you should use std::basic_string<char32_t>, but this requires a compiler with some C++0x support.

Solution 2

The size of wchar_t is platform-dependent and it is independent of UTF-8, UTF-16, and UTF-32 (it can be used to represent unicode data, but there is nothing that says that it represents that).

I strongly recommend using UTF-8 with std::string for internal string representation, and using established libraries such as ICU for complex manipulation and conversion tasks involving unicode.

Solution 3

The ICU open source library would help, but base Windows/VS2010 won't help you.

Share:
12,451
user963241
Author by

user963241

Updated on June 04, 2022

Comments

  • user963241
    user963241 almost 2 years

    is there 32-bit wide character for encoding UTF-32 strings? I'd like to do it via std::wstring which apparently showing me size of a wide character is 16 bits on windows platform.