CString 写入文件是双字节?解决方案
CString 写入文件是双字节?
CString 写入文件是双字节? 如: 写入字符串:http--> 真实内容: h.t.t.p --> 十六进制:68 00 74 00 74 00 70 00
怎么样才能原样写入http ????
下面两种办法的结果一样:
//FILE * pFile = _wfopen(fileDlg.m_szFileName, _T( "w+ "));
//fwrite(m_strOut, m_strOut.GetLength(), 1, pFile);
//fflush(pFile);
//fclose(pFile);
HANDLE hFile;
DWORD dwRet = 0;
hFile = CreateFile(fileDlg.m_szFileName, // file to create
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_ALWAYS, // overwrite existing
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
WriteFile(hFile, m_strOut , lstrlen(m_strOut) * sizeof(char), &dwRet, NULL);
CloseHandle(hFile);
------解决方案--------------------
是否已经设成了Unicode工程模式?
------解决方案--------------------
自己写一个buffer类处理文件操作,CString在内部处理了字节问题。
------解决方案--------------------
两个办法:一是改成非unicode模式,但是你其他地方的一些代码可能需要修改。
另外的办法是定义char buf[100];使用W2A宏进行转换,也可以使用Api来转换。
CString 写入文件是双字节? 如: 写入字符串:http--> 真实内容: h.t.t.p --> 十六进制:68 00 74 00 74 00 70 00
怎么样才能原样写入http ????
下面两种办法的结果一样:
//FILE * pFile = _wfopen(fileDlg.m_szFileName, _T( "w+ "));
//fwrite(m_strOut, m_strOut.GetLength(), 1, pFile);
//fflush(pFile);
//fclose(pFile);
HANDLE hFile;
DWORD dwRet = 0;
hFile = CreateFile(fileDlg.m_szFileName, // file to create
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_ALWAYS, // overwrite existing
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
WriteFile(hFile, m_strOut , lstrlen(m_strOut) * sizeof(char), &dwRet, NULL);
CloseHandle(hFile);
------解决方案--------------------
是否已经设成了Unicode工程模式?
------解决方案--------------------
自己写一个buffer类处理文件操作,CString在内部处理了字节问题。
------解决方案--------------------
两个办法:一是改成非unicode模式,但是你其他地方的一些代码可能需要修改。
另外的办法是定义char buf[100];使用W2A宏进行转换,也可以使用Api来转换。