我正在尝试设置目标文件夹以及目标文件路径以将其自身复制到新位置,但是我正在使用 strcpy 和 strcat
argument of type "TCHAR *" is incompatible with parameter of type "char *"
如何保持相同的代码结构和行为以将文件自行复制到新位置?
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;
}
最佳答案
您正在使用 TCHAR
,因此请将 strcpy()
替换为 _tcscpy()
和 strcat()
使用 _tcscat()
。
关于c++ - 自复制文件到新位置 tchar 与 char 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56247400/