我试图设置目标文件夹以及目标文件路径以将自身复制到新位置,但是我正在使用strcpy , and strcat
“ TCHAR *”类型的参数与类型的参数不兼容 “字符*”
如何保持相同的代码结构和行为,以将文件自动复制到新位置?
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR szFilepath[MAX_PATH];
TCHAR szFilename[MAX_PATH];
TCHAR szDestpath[MAX_PATH];
/* Get the current executable's full path */
GetModuleFileName(NULL, szFilepath, MAX_PATH);
std::wcout << "filepath: " << szFilepath << std::endl;
/* Extract just the name */
GetFileTitle(szFilepath, szFilename, MAX_PATH);
std::wcout << "filename: " << szFilename << std::endl;
//Set the destination folder path
strcpy(szDestpath, "D:\\");
//Set the destination file path
strcat(szDestpath, szFilename);
std::wcout << "dest path: " << szDestpath << std::endl;
// copys the file of your '.exe'
if (!CopyFile(szFilepath, szDestpath, FALSE)) {
std::cout << "couldnt copy the file";
}
else {
std::cout << "good";
}
return 0;
}
答案 0 :(得分:2)
您正在使用TCHAR
,因此将strcpy()
替换为_tcscpy()
,并将strcat()
替换为_tcscat()
。