1
这行代码工作正常。如何将字符串转换为u8?
#include <cstdlib>
#include <iostream>
#include <locale.h>
#include <string>
#include <locale>
#include <codecvt>
#include <cassert>
int main() {
const auto str = u8"حخدذرزژس";
wstring_convert<codecvt_utf8<char32_t>, char32_t> cv;
auto str32 = cv.from_bytes(str);
for (auto c : str32)
cout << uint_least32_t(c) << '\n';
return 0;
}
我需要从文件中读取字符串“حخدذرزژس”。
如何初始化const auto str
与从文件中读取的字符串以获得与上述代码相同的答案?
@ OLIVER.KOO:他想从文件中读取 –
'basic_string'不知道关于它的编码的任何信息。如果您的文件包含UTF8字符串,则只需从文件中读取它,就像读取任何其他字符串一样。 – Paul
只是打开并阅读文件 –