在写一个读档和写档的练习,其实是从msdn范例作小修改而已,环境是VS2005,类型是主控应用程序,设定支援MFC库,Compile时总是出现:error C2664:
'CFile:: Open' : 无法将参数 1从 'const char [11]' 转换成'LPCTSTR'
这是因为:VS2005使用Unicode字元集, 字串必须转换成Unicode字串才可以使用, 而
'CFile:: Open' : 无法将参数 1从 'const char [11]' 转换成'LPCTSTR'
程序如下:
Code Snippet
CFile sourceFile;
CFile destFile;
CFileException ex;
// open the source file for reading
if (!sourceFile.Open("TP20060207",CFile::modeRead | CFile::shareDenyWrite, &/
ex))
{
:
}
但若改成下面的方式,就能通过 Code Snippet
CFile sourceFile;
CFile destFile;
CFileException ex;
LPCTSTR strFileName=L"TP20060207";
if (!sourceFile.Open(strFileName,CFile::modeRead | CFile::shareDenyWrite, &ex))
{
:
}
L"TPXXX";
中的L, 就是将字串转换成Unicode的元集