How to convert ASCII string to UTF8 string in C ++?

How to convert ASCII std :: string to UTF8 (Unicode) std :: string in C ++?

+3
source share
3 answers
std::string ASCIIToUTF8(std::string str) {
  return str;
}

Each ASCII character has the same representation in UTF8, so there is nothing to convert. Of course, if the input string uses an extended (8-bit) ASCII character set, the answer is more complex.

+5
source

ASCII is a seven-bit encoding and identically displays the UTF-8 encoding of the subset of characters that can be represented in ASCII.

In short, there is nothing to do. Your ASCII string is already valid UTF-8.

+2
source

, ASCII CP1252 8- (ASCII - 7 UTF-8, ). ++ . , , Glibmm, Qt, iconv WINAPI, .

0
source

Source: https://habr.com/ru/post/1734683/


All Articles