Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use unicode in C++ without much pain?

In C++ there’s no solid standard when it comes to encoding. If I want to use unicode, for example, UTF-8 in C++ for Windows, how can I achieve that?

  1. On Windows I have to use something like wide-strings to use unicode, is it the only way?
  2. If I have to use third-party libraries, what libraries do you can advise?
  3. What I have to remember when using unicode instead of std::string?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you are talking about source code, then its implementation specific for each compiler, but I believe every modern compiler supports UTF-8 at least.

C++ itself has following types to support Unicode:
wchar_t, char16_t, char32_t and char8_t for characters and corresponding std::wstring, std::u16string, std::u32string and std::u8string for strings.

And following notations for literals:

char8_t ch_utf8 = u8'c';
char16_t ch_utf16 = u'c';
char32_t ch_utf32 = U'C';
wchar_t ch_wide = L'c';

char8_t str_utf8[] = u8"str";
char16_t str_utf16[] = u"str";
char32_t str_utf32[] = U"str";
wchar_t str_wide[] = L"str";

std::codecvt template for string conversions between different encodings.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading