windows 10 c语言 unicode 读写文件的问题
我有一个UNICODE写的文件
我读取的时候
FILE* pSt_File = _tfopen(_T("D:\\1\\x64\\Debug\\1.txt"), _T("r+"));
if (NULL == pSt_File)
{
int nRet = errno;
return FALSE;
}
int nMsgLen = 1024;
TCHAR* ptszMsgBuffer = (TCHAR*)malloc(1024);
if (NULL == ptszMsgBuffer)
{
return FALSE;
}
memset(ptszMsgBuffer, '\0', 1024);
size_t nRet = fread(ptszMsgBuffer, sizeof(TCHAR), 1024, pSt_File);
fclose(pSt_File);
fread 永远返回0 ,但是我改成 fread(ptszMsgBuffer, sizeof(CHAR), 1024, pSt_File);
就正常了,为啥unicode下参数2要1个字节大小啊?