Is there C# Encoding.UTF8.GetString
equivalent in C++ ? Or another fast way parse byte array containing the sequence of bytes and decode to string.
Asked
Active
Viewed 1,598 times
2

Cipher
- 352
- 1
- 11
-
2Check this one: http://stackoverflow.com/questions/16208079/how-to-work-with-utf-8-in-c-conversion-from-other-encodings-to-utf-8 – Fruchtzwerg May 17 '16 at 12:07
-
Is good solution but I can't parse byte array by `index` such as `Encoding.UTF8.GetString(byte[], index int, count int);`. – Cipher May 17 '16 at 12:51
-
1The answer depends a lot on what you mean by "string". The closest to C#'s `String` is probably `std::wstring`, in which case you may be looking for `std::wstring_convert
>().from_bytes(your_utf8_byte_ptr)` – Igor Tandetnik May 18 '16 at 04:46
1 Answers
1
You can try this:
auto *wstrBytes = new wchar_t[size];
memcpy_s(wstrBytes , size, rawBytes, size);
std::wstring unicodeStr(wstrBytes , size);
delete [] wstrBytes;

Moshe Slavin
- 5,127
- 5
- 23
- 38

Praveen Patel
- 429
- 4
- 11