我需要將utf16文本轉換爲utf8。實際的轉換代碼很簡單:努力將矢量<char>轉換爲wstring
std::wstring in(...);
std::string out = boost::locale::conv::utf_to_utf<char, wchar_t>(in);
但問題是UTF16是從文件中讀取的,它可能包含或不包含BOM。我的代碼需要可移植(最低限度是windows/osx/linux)。我真的很想弄清楚如何從字節序列創建一個wstring
。
編輯:這不是一個鏈接問題的重複,因爲在那個問題OP需要將寬字符串轉換爲字節數組 - 我需要轉換其他方式。
我不確定,會[此帖](https://stackoverflow.com/questions/2573834/c-convert-string-or-char-to-wstring-or-wchar-t)有幫助嗎? – gongzhitaao
如何將'vector'轉換爲'wstring'? –
SirDarius
@SirDarius嗯,這正是我的問題:如何從'vector'獲取'wstring'? –