c++ - 用于执行 C++ 系统函数的用户定义目录

标签 c++ system

system("mkdir C:\\Users\\USER\\Desktop\\test");

我找到了这个但是这不起作用因为我的代码看起来像这样

string inputFAT = "input.FAT";
    string outputdirecotry = "adirectory";
    string exepath = "FATool.exe";

    cout << "enter the directory you would like to have the files put out to";
    getline(cin, outputdirecotry);
    string outputdirectorycommand = "cd " + outputdirecotry;


    cout << "enter the path of the file you want to extract";
    getline(cin, inputFAT);

    cout << "enter the path to the FATool executable";
    getline(cin, exepath);

    string  exportcommand = exepath + " -x " + inputFAT;
    system(outputdirectorycommand.c_str && exportcommand.c_str());

如你所见,我需要用户定义系统功能需要进入的目录,当我尝试构建它时,它会抛出这些错误

Severity Code Description Project File Line Suppression State Error C3867 'std::basic_string,std::allocator>::c_str': non-standard syntax; use '&' to create a pointer to member FATool++ c:\users\russ\documents\visual studio 2015\projects\fatool++\fatool++\main.cpp 24

还有这个

Severity Code Description Project File Line Suppression State Error C2664 'int system(const char *)': cannot convert argument 1 from 'bool' to 'const char *' FATool++ c:\users\russ\documents\visual studio 2015\projects\fatool++\fatool++\main.cpp 24

所以有没有可能做到这一点,或者我应该自己承担损失并自己定义目录,让我的 friend 进入代码并做同样的事情

最佳答案

传递给system()的参数是错误的:

system(outputdirectorycommand.c_str && exportcommand.c_str());

语法 outputdirectorycommand.c_str是错误的,传递给system()的参数是bool这显然是错误的。

假设你想做的是执行cd <x> && FATool.exe -x <xxx> , 那么你应该 cat您的命令并将其传递给 system() :

string cmdToExecute = outputdirectorycommand + " && " + exportcommand;
system(cmdToExecute.c_str());

关于c++ - 用于执行 C++ 系统函数的用户定义目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38711292/

相关文章:

java - Android 中的 System.out.println?

macos - 如何从 go 启动 vim?

c++ - 命令失败时,gzip 会在 C++ 中返回错误代码吗?

c++ - 如何制作包含唯一指针的类的标准列表

c++ - 类和线性回归

c++ - 我可以将 Boost.Geometry.index.rtree 与线程一起使用吗?

c++ - 使用基于自动的 Ranged for 循环与使用基于对的 Ranged for 循环

c++ - 如何在 C++ 中 "modify"系统 ("pause")

linux - 我正在尝试创建 payara 集群,但在创建远程节点期间出现错误

c++ - 是否有像 Pycharm 那样检查编码风格的 C++ IDE?