输出的文件里,中文变成问号,求助
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define LOGFILE "./LogFile.txt" // 具体的文件名
int WriteToLog(TCHAR* str)
{
FILE* log;
int errno_t = fopen_s(&log,LOGFILE,"a+");
if(!log)
return -1;
_ftprintf_s(log,_T("%s\n"),str);
fclose(log);
return 0;
}
void ErrorExit(LPTSTR lpszFunction)
{
TCHAR szBuf[80];
LPVOID lpMsgBuf;
DWORD dw = GetLastError(); // it can retrieve the last-error code
// formats a message string
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | // 给参数分配空间
FORMAT_MESSAGE_FROM_SYSTEM, // 消息来自系统表(另外还可以来自模块表,字符串)
NULL,
dw, // 错误号
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, // 如果参数没有自动设定,就设定,反之忽略
NULL // 参数表
);
wsprintf(szBuf, _T("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf);
WriteToLog(szBuf);
LocalFree(lpMsgBuf);
}
int main()
{
WriteToLog(_T("开始:"));
ErrorExit(_T("错误"));
return 0;
}
程序运行后,日志文件中凡是中文的地方都变成了问号?
求助,怎么回事?怎么修改?