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());
你可以看到我需要用户定义系统函数需要去的目录,当我尝试构建它时会抛出这些错误
严重级代码描述项目文件行抑制状态 错误C3867&#39; std :: basic_string,std :: allocator&gt; :: c_str&#39 ;:非标准语法;使用&#39;&amp;&#39;创建指向成员FATool ++的指针c:\ users \ russ \ documents \ visual studio 2015 \ projects \ fatool ++ \ fatool ++ \ main.cpp 24
还有这个
严重级代码描述项目文件行抑制状态 错误C2664&#39; int system(const char *)&#39;:无法转换参数1来自&#39; bool&#39;到#char; char *&#39; FATool ++ c:\ users \ russ \ documents \ visual studio 2015 \ projects \ fatool ++ \ fatool ++ \ main.cpp 24
所以甚至可以做到这一点,或者我应该自己动手并自己定义目录并让我的朋友进入代码并做同样的事情
答案 0 :(得分:1)
传递给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());
答案 1 :(得分:1)
system(outputdirectorycommand.c_str && exportcommand.c_str());
这会尝试获取std :: string :: c_str函数的地址,将其转换为bool和logical-并使用exportcommamd.c_str()的返回值的bool转换对其进行测试。
你可能打算
system(outputdirectorycommand.c_str() + " && " + exportcommand.c_str());