[問題] 請教wofstream為何會把CRLF 變成CRCRLF呢
看板C_and_CPP (C/C++)作者donkeychen (Bad_To_The_Bone)時間12年前 (2013/11/25 14:45)推噓4(4推 0噓 12→)留言16則, 4人參與討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
boost
問題(Question):
我做一個wofstream的輸出
資料原本CRLF的部分在輸出後的檔案都變成CRLF
餵入的資料(Input):
http://ppt.cc/sh90
如圖 在debug mode裡面 看string還是 49 13 10 ("1" 0x0d 0x0a)
預期的正確結果(Expected Output):
49 13 10 ("1" 0x0d 0x0a)
錯誤結果(Wrong Output):
http://ppt.cc/isho
都是 49 13 13 10 ("1" 0x0d 0x0d 0x0a)
程式碼(Code):(請善用置底文網頁, 記得排版)
std::locale old_locale;
std::locale utf8_locale(old_locale,new \
boost::program_options::detail::utf8_codecvt_facet);
filesystem::wpath asPath(path);
wofstream myfile;
// myfile.imbue(utf8_locale); //這行有沒有都會這結果
if(!myfile.is_open())
{
myfile.open(asPath.external_file_string().c_str(), ios::in | ios::out | \
ios::app | ios::ate);
}
if((myfile.rdstate() & std::ifstream::failbit) != 0)
{
std::string strError = strerror(errno);
myfile.clear();
}
else
{
myfile << message << L"\x0d\x0a;
}
myfile.close();
補充說明(Supplement):
由於懷疑是因為用imbue(utf8_locale)的關係
有將其中一行註解
但是都是一樣的結果
想請教一下大家是有哪邊弄錯嗎 感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.59.147.226
※ 編輯: donkeychen 來自: 210.59.147.226 (11/25 14:46)
推
11/25 15:10, , 1F
11/25 15:10, 1F
推
11/25 16:05, , 2F
11/25 16:05, 2F
→
11/26 11:11, , 3F
11/26 11:11, 3F
推
11/30 20:37, , 4F
11/30 20:37, 4F
→
11/30 20:38, , 5F
11/30 20:38, 5F
→
11/30 20:38, , 6F
11/30 20:38, 6F
→
12/04 16:36, , 7F
12/04 16:36, 7F
→
12/04 16:38, , 8F
12/04 16:38, 8F
→
12/04 16:38, , 9F
12/04 16:38, 9F
推
12/14 13:12, , 10F
12/14 13:12, 10F
→
12/14 13:13, , 11F
12/14 13:13, 11F
→
12/14 13:16, , 12F
12/14 13:16, 12F
→
12/14 13:18, , 13F
12/14 13:18, 13F
→
01/06 11:58, , 14F
01/06 11:58, 14F
※ 編輯: donkeychen 來自: 210.59.147.226 (01/06 11:59)
→
01/06 12:01, , 15F
01/06 12:01, 15F
→
01/06 12:02, , 16F
01/06 12:02, 16F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
10
15