CFile readFile, writeFile;
//读取txt文件
if(readFile.Open(CBApp::getCurrModulePath()+_T("filename.txt"), CFile::modeRead))
{
//ansi to unicode
int iFileLenth = (int)readFile.GetLength();
char* cRead = new char[iFileLenth];
readFile.Read(cRead, iFileLenth);
readFile.Close();
//预转换,得到所需空间的大小
iLen = ::MultiByteToWideChar(CP_ACP, NULL, cRead, iFileLenth, NULL, 0);
wchar_t* cTemp = new wchar_t[iLen + 1]; //留一个位置给'\0'
::MultiByteToWideChar(CP_ACP, NULL, cRead, iFileLenth, cTemp, iLen);//转换
cTemp[iLen] = '\0';
sFileName= cTemp;
delete cRead;
delete cTemp;
}
//创建或写入txt文件
writeFile.Open(CBApp::getCurrModulePath()+_T("filename.txt"), CFile::modeWrite | CFile::modeCreate );
LPTSTR pTemp = sFileName.GetBuffer();
//unicode to ansi
iLen = ::WideCharToMultiByte(CP_ACP, NULL, pTemp, (int)wcslen(pTemp), NULL, 0, NULL, NULL);
char* cWrite = new char[iLen + 1];
::WideCharToMultiByte(CP_ACP, NULL, pTemp, (int)wcslen(pTemp), cWrite, iLen, NULL, NULL);
cWrite[iLen] = '\0';
writeFile.Write(cWrite, iLen);
writeFile.Close();
delete cWrite;
CFile readFile, writeFile;
//读取txt文件
if(readFile.Open(CBApp::getCurrModulePath()+_T("filename.txt"), CFile::modeRead))
{
//ansi to unicode
int iFileLenth = (int)readFile.GetLength();
char* cRead = new char[iFileLenth];
readFile.Read(cRead, iFileLenth);
readFile.Close();
//预转换,得到所需空间的大小
iLen = ::MultiByteToWideChar(CP_ACP, NULL, cRead, iFileLenth, NULL, 0);
wchar_t* cTemp = new wchar_t[iLen + 1]; //留一个位置给'\0'
::MultiByteToWideChar(CP_ACP, NULL, cRead, iFileLenth, cTemp, iLen);//转换
cTemp[iLen] = '\0';
sFileName= cTemp;
delete cRead;
delete cTemp;
}
//创建或写入txt文件
writeFile.Open(CBApp::getCurrModulePath()+_T("filename.txt"), CFile::modeWrite | CFile::modeCreate );
LPTSTR pTemp = sFileName.GetBuffer();
//unicode to ansi
iLen = ::WideCharToMultiByte(CP_ACP, NULL, pTemp, (int)wcslen(pTemp), NULL, 0, NULL, NULL);
char* cWrite = new char[iLen + 1];
::WideCharToMultiByte(CP_ACP, NULL, pTemp, (int)wcslen(pTemp), cWrite, iLen, NULL, NULL);
cWrite[iLen] = '\0';
writeFile.Write(cWrite, iLen);
writeFile.Close();
delete cWrite;