[英]How to convert file from windows utf-16 or windows utf-8 to unix utf-16 with C++
現在,我們在Windows上使用C ++處理一些數據。 我們必須將一些文件轉換為unix uft-16的xml,這些xml文件存儲在Unix服務器上。
所以我想知道如何使用C ++將文件從Windows utf-16或Windows utf-8轉換為Unix utf-16?
需要使用codecvt標頭的std :: codecvt_utf8_utf16可用於將UTF-8轉換為UTF-16。 此鏈接的樣本。 需要支持C ++ 11的編譯器。
// codecvt_utf8_utf16 example
#include <iostream>
#include <locale>
#include <string>
#include <codecvt>
int main ()
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> conversion;
std::string mbs = conversion.to_bytes( u"\u4f60\u597d" ); // ni hao (你好)
// print out hex value of each byte:
std::cout << std::hex;
for (int i=0; i<mbs.length(); ++i)
std::cout << int(unsigned char(mbs[i])) << ' ';
std::cout << '\n';
return 0;
}
可以在上述鏈接中找到更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.