Unicode到Multi-byte的转换
需要使用到WideCharToMultiByteint WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
_In_NLS_string_(cchWideChar)LPCWCH lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCCH lpDefaultChar,
LPBOOL lpUsedDefaultChar
);
函数fread fwrite用来读写二进制数据, 函数fgets会把行末的换行符\n给读取进来。
示例代码如下:static int WideChar2TChar(wchar_t *wc, char *tc)
{
DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wc,-1,NULL,0,NULL,FALSE);
char *TC = new char[dwNum];
if(!TC)
return 1;
WideCharToMultiByte(CP_OEMCP,NULL,wc,-1,TC,dwNum,NULL,FALSE);
memcpy(tc, TC, dwNum);
tc[dwNum] = 0;
delete []TC;
return 0;
}
// trim the '\n'
static void delreturn(wchar_t *b, int n, FILE *f)
{
if(fgetws(b, n, f) != NULL)
b[wcslen(b) - 1] = 0; // trim
}