c++ - 自复制文件到新位置 tchar 与 char 不兼容

标签 c++

我正在尝试设置目标文件夹以及目标文件路径以将其自身复制到新位置,但是我正在使用 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/

相关文章:

c++ - 无法使用 clang_complete 完成 qt

映射中的 C++ 结构作为值 - 错误 "no instance of overloaded function matches the argument list"

c++ - 需要帮助查找内存泄漏

c++ - 通过构造时获取的指针修改const对象

c++ - Q_PROPERTY NOTIFY 信号及其参数

c++ - 正则表达式无法通过 getline() 输入正常工作

c++ - std::get_time 不适用于 visual studio 2012 中的日期

c++ - 对我的绘图项目的建议

c++ - QFileDialog 允许选择多个目录但不返回它们

c++ - 如何从 C++ 中的 DLL 导出纯虚函数?