... <看更多>
「_wfopen」的推薦目錄:
- 關於_wfopen 在 [問題] UTF-8 Read / Write - 看板C_and_CPP - 批踢踢實業坊 的評價
- 關於_wfopen 在 Is it possible to refactor _wfopen to std::filesystem? - Stack ... 的評價
- 關於_wfopen 在 in C _wfopen doesn't use demanded encoding UNICODE #403 的評價
- 關於_wfopen 在 _wfopen failed on Windows - githubmemory 的評價
- 關於_wfopen 在 Fix - unsafe _wfopen and _wfreopen in Visual Studio · kuba 的評價
_wfopen 在 in C _wfopen doesn't use demanded encoding UNICODE #403 的推薦與評價
On windows x64 with open-watcom-2.0-2017-11-01, I do: wchar_t lBuff[1024]; FILE * lIn = _wfopen(myFileName, L"rt, ccs=UNICODE"); ... ... <看更多>
_wfopen 在 _wfopen failed on Windows - githubmemory 的推薦與評價
When I try to use NCNN on Windows, it stops with _wfopen G:\tmp\Cupscale\Models\.ncnn\1x_BC1-smooth2/x4.param failed . The last / should be a \ on Windows. ... <看更多>
_wfopen 在 Fix - unsafe _wfopen and _wfreopen in Visual Studio · kuba 的推薦與評價
A portable, simple zip library written in C. Contribute to kuba--/zip development by creating an account on GitHub. ... <看更多>
_wfopen 在 [問題] UTF-8 Read / Write - 看板C_and_CPP - 批踢踢實業坊 的推薦與評價
開發平台(Platform): (Ex: Win10, Linux, ...)
Visual Studio 2017 , Console C/C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
[Q1]
目前我收到的檔案,用記事本開、notepad++開,
一般 asci 是用 1 byte , 繁中、簡中(非常少數)是用 2 byte 存,
再用記事本去開,預設是用 utf-8 存 (非 asci),且無 bom 檔頭 ,
所以我是否可以假設這份檔案是以 utf-8 方式存檔?
[Q2]
目前我嚐試過用 fopen / _wfopen 方式去開、讀檔 ,
也試過指定 ccs=UTF-8 方式去開 ,
再做簡單的 printf / wprintf , 不論怎麼改跑出來的一直都是亂碼 ,
最後嚐試用 char , 直接輸出到檔案去 , 神奇的事發生了
console 輸出是亂碼 , 檔案全都解得出來
去細節後 code 摘要如下
FILE * fin = fopen(sfilename.c_str(), "rb,ccs=UTF-8");
char * pBuf = (char *)malloc(filesize + 32);
fread((void*)pBuf, 1, filesize, fin);
pBuf[filesize] = 0;
FILE * fout = fopen("output.txt", "w");
pFind = pBuf;
while (pFind = strstr(pFind, pszDesc)) {
pFindNext = strstr(pFind + iDescLen, pszScore);
if (pFindNext == NULL) break;
*(pFindNext - 1) = 0;
fprintf(stdout, "%s\n", pFind); \\ 亂碼
fprintf(fout, "%s\n", pFind); \\ 正常
pFind = pFindNext + 1;
}
fclose(fout);
free(pBuf);
請問是不是我誤會了什麼東西?
若要解析這種檔案, 請問我的方法正確嗎?
另若有版友建議直接加入 ATL CString 處理編碼的話也請告知
(乍看只換 CString 問題應該不會改善)
[Q3]
最後的問題是 , 這些截出來的字串會丟到簡易型 db,
之前碰過 sqlite , 但只用過 asci 編碼 , 查了下官網 ,
sqlite 應是支援 utf-8 , 請問這方面是否有人有過經驗能給些意見?
或是直接丟掉 sqlite , 有其他較簡易但字元編碼較佳的 sql lib ?
最後謝謝各位細心回覆,感激不盡。
--
就算把新鮮的肝拿回去,還是一樣寫碼到禿頭,加班到天亮,
永遠當老闆的傀儡 你是不是想這麼做?
是的話你就拿回去~ 拿啊!!
九世宅男 : 下輩子不要再讓我幹工程師了 ~
< Kuso 星爺語錄 >
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.72.2
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1521226295.A.2A0.html
... <看更多>