簡體   English   中英

將包含存儲在字符串中的.gzip數據的UTF-8文本保存到文件C ++

[英]Saving UTF-8 text containing .gzip data stored in a string to file C++

如標題所示,使用C ++時,我在從字符串保存UTF-8文本時遇到了一些問題。 我可以確認該字符串具有正確的數據,但是在不丟失部分.gzip數據的情況下,我無法將其寫入文件。

請注意:1. ofstream不支持utf-8。 2.這僅適用於Windows,不需要通用。 3.最好不要解壓縮.gzip,因為它與字符串混合在一起。

我正在使用這個: http : //mariusbancila.ro/blog/2008/10/20/writing-utf-8-files-in-c/

這是代碼:

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;

std::wstring wide = converter.from_bytes(packetString); // Will not go past here for some reason.

std::ofstream testFile;

testFile.open("C:\\output", std::ios::out | std::ios::binary);

std::string outtext = to_utf8(wide);

testFile << outtext;

testFile.close();

當它包含ASCII和UTF-8的混合字符串時,我很難獲取此代碼來轉換我的字符串,而且我真的不確定為什么它在注釋行處失敗。

testFile.write(packetString.data(), packetString.size())

我不好,這是我需要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM