gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 02:02:50 28 4
gpt4 key购买 nike

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com