V
V
Vladimir Onokhov2021-06-23 14:24:05
C++ / C#
Vladimir Onokhov, 2021-06-23 14:24:05

When is it better to use wchar_t, char16_t, char32_t instead of char in C++?

I read it, but I didn't fully understand it.
C++20 standard.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2021-06-23
@teralph2d

In cases where you want to use UTF-16LE, UTF-16 or UTF-32 respectively.
If you want to use an eight-bit encoding or UTF-8, then take char or char8_t, the latter is made specifically for UTF-8

E
Evgeny Petryaev, 2021-06-23
@Gremlin92

wchar_t is used when it is necessary to input/output strings to winapi graphical components

R
res2001, 2021-06-23
@res2001

Under Windows, it's better to always use wchar_t, because The Windows kernel internally uses wchar_t for strings. All WinAPI functions that accept strings as char* simply convert them to wchar_t and call the appropriate function for wide characters. So for some optimization it is better to use wchar_t right away.
In Linux, UTF8 is now ubiquitous. Unless you have to write for older kernels/distributions.
Other types - then when you work with data in the appropriate encodings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question