读utf-8文件:
FILE *fileHandle=_wfopen(_T("1.txt"), _T("r, ccs=UTF-8"));
if (fileHandle!=NULL)
{
long fileSize=ftell(fileHandle);
wchar_t linex[1000];
int iLine=0;
while (!feof(fileHandle))
{
iLine++;
memset(linex,0,1000);
fgetws(linex,1000,fileHandle);//一行一行得到
//wcout<<linex;
CString strLine;
strLine.Format(_T("%d\t%s"),iLine,linex);
AfxMessageBox(strLine);
}
fclose(fileHandle);
}
写utf-8文件:
FILE *fileHandle=_wfopen(_T("1.txt"), _T("a, ccs=UTF-8"));
if (fileHandle!=NULL)
{
CString strToWriteHead;
strToWriteHead.Format(_T("------------------\n"));
if (fwrite(strToWriteHead, sizeof(wchar_t), strToWriteHead.GetLength(), fileHandle) != strToWriteHead.GetLength())
{
wprintf(L"fwrite failed!\n");
}
fclose(fileHandle);
}

1096

被折叠的 条评论
为什么被折叠?



