0

以下代码要求用户命名文件夹。使用用户输入创建一个目录,例如 C\test\user input\disk1。使用 SHfile 操作,我想将 A 驱动器中的所有文件传输到字符串变量 disk1T 中包含的用户定义路径中。该程序无法编译,我收到以下错误。

C:\C++\file\main.cpp|39|错误:在初始化中无法将 'std::__cxx11::string {aka std::__cxx11::basic_string}' 转换为 'const wchar_t* const'|

有人有什么想法吗?

#include <iostream>
#include <stdlib.h>
#include <windows.h>
#include <stdio.h>

using namespace std;

int main()
{
    string input1 = "C:\\test\\";
    string input2 = "";
    string total2 = "";
    cout << "Please enter the name of the folder:\n>";
    getline(cin, input2);

    string total = input1+input2;
    string disk1 = "\\disk1";
    string disk1T = total+disk1;   //Complete path of folder e.g. C:\\test\abc\disk1

   //Create the directories
   CreateDirectory(total.c_str(),NULL);
   CreateDirectory(disk1T.c_str(),NULL);


     const wchar_t *const sourceFile= L"A:\\*.*\0";   // All files are copied from floppy disk

     const wchar_t *const outputFile= disk1T; //User defined destination e.g. C:\\test\abc\disk1. The compiler error occurs here.


    SHFILEOPSTRUCTW fileOperation;
    memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));

    //fileOperation.FOF_FILESONLY = true;
    fileOperation.wFunc = FO_COPY;
    fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY;
    fileOperation.pFrom = sourceFile;
    fileOperation.pTo = outputFile;


    int result = SHFileOperationW(&fileOperation);
    if (result != 0)
    {
        printf("SHFileOperation Failure: Error%u\n", result);
        return 1;
    }

    memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW));

    printf("Transfer complete w\n");

   return 0;

}
4

0 回答 0