argument of type "const char*" is incompatible with parameter of type "LPCTS”
下列代码。红色部分会报错:
argument of type "const char*" is incompatible with parameter of type "LPCTS”
还请大侠们帮忙看下怎么改,感谢了。
#include <iostream>
#include <fstream>
#include <vector>
#include <windows.h>
#include <string>
using namespace std;
HANDLE hfile;
BOOL FindNextFile
(
HANDLE hFindFile, //searchhandle
LPWIN32_FIND_DATA lpFindFileData //databuffer
);
HANDLE FindFirstFile
(
LPCTSTR lpFileName,//filename
LPWIN32_FIND_DATA lpFindFileData//databuffer
);
BOOL CopyFile(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, BOOL bFailIfExists);
BOOL DeleteFile(LPCSTR lpFileName);
typedef const TCHAR FAR * LPCTSTR;
int main()
{
const string fileform = ".log";//读取文件格式
string perfileReadPath = "E:\KR1\ka3\ka3";//指定读取的目录
const int perclass_sample = 20;//读取的最大个数
string fileReadPath = perfileReadPath + fileform;
string fileTemp = perfileReadPath + "temp.csv";//临时文件
string fileWritePath = perfileReadPath +"data_file.csv";//最终结果文件
WIN32_FIND_DATA pNextInfo;
HANDLE hFile = FindFirstFile(fileReadPath.c_str(), &pNextInfo);
if(hFile == INVALID_HANDLE_VALUE)
{
cout<<"文件不存在"<<endl;
exit(-1);
}
char chTemp[1024+1],chTxt[1024+1],chWrite[1024+1];
DeleteFile(fileTemp.c_str());//如果存在临时文件,则删除
int iCount=0;//文件个数
do
{
if(pNextInfo.cFileName[0] == '.')
continue;//不读取文件夹
string txtFilename = perfileReadPath + pNextInfo.cFileName;//当前读取的txt文件
FILE * srcFile,*tempFile,*desFile;
srcFile = fopen(txtFilename.c_str(),"r+");//打开当前读取的txt文件
tempFile = fopen(fileTemp.c_str(),"r+");//打开临时文件
desFile = fopen(fileWritePath.c_str(),"w+");//打开结果文件
while( !feof(srcFile) || (tempFile!=NULL && !feof(tempFile)))
{
memset(chTxt,0,1024);
memset(chTemp,0,1024);
if (tempFile!=NULL &&!feof(tempFile)) fgets(chTemp,1024,tempFile);//读取临时文件的整行数据
if (!feof(srcFile))
{
fgets (chTxt,1024,srcFile);//读取txt的整行数据
//-------------------------------------------
//此段代码是为了对齐格式,当临时文件读取到结尾,而txt没有读取到结尾,
//把当前的txt数据放到指定的列
if (tempFile!=NULL &&feof(tempFile))
{//临时文件不为空,但读取到结尾
for (int j = 0; j < iCount ; j++)
{
chTemp[j] = ',';
}
}
//--------------------------------------------
}
if (chTxt[strlen(chTxt)-1] == '\n')
chTxt[strlen(chTxt)-1] = '\0';//如果读取到的行数据,结尾是换行,则删除
if (chTemp[strlen(chTemp)-1] == '\n')
chTemp[strlen(chTemp)-1] = '\0';//如果读取到的行数据,结尾是换行,则删除
//最终结果文件结尾不添加换行
if (!feof(srcFile) || (tempFile!=NULL && !feof(tempFile)))
{
sprintf(chWrite,"%s%s,\n",chTemp,chTxt);
}else sprintf(chWrite,"%s%s,",chTemp,chTxt);
fputs(chWrite,desFile);//写入结果文件
}
if (srcFile != NULL) fclose (srcFile);//关闭文件
if (tempFile != NULL) fclose (tempFile);//关闭文件
if (desFile != NULL) fclose (desFile);//关闭文件
CopyFile(fileWritePath.c_str(),fileTemp.c_str(),FALSE);// 把结果csv文件拷贝到临时csv文件。
iCount++;//文件个数
}while (FindNextFile(hFile,&pNextInfo) && iCount<perclass_sample);
DeleteFile(fileTemp.c_str());//删除临时文件
return 0;
}