用于执行 C++ 系统函数的用户定义目录
User defined directory for a c++ system function to execute from
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
是否可以这样做,或者我应该自己承担损失并自己定义目录并让我的朋友进入代码并做同样的事情
传递给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());
system(outputdirectorycommand.c_str && exportcommand.c_str());
这尝试获取 std::string::c_str 函数的地址,将其转换为 bool 和逻辑 - 并使用 exportcommamd.c_str 的 return 值的 bool 转换测试它( ).
你可能有意
system(outputdirectorycommand.c_str() + " && " + exportcommand.c_str());
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
是否可以这样做,或者我应该自己承担损失并自己定义目录并让我的朋友进入代码并做同样的事情
传递给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());
system(outputdirectorycommand.c_str && exportcommand.c_str());
这尝试获取 std::string::c_str 函数的地址,将其转换为 bool 和逻辑 - 并使用 exportcommamd.c_str 的 return 值的 bool 转换测试它( ).
你可能有意
system(outputdirectorycommand.c_str() + " && " + exportcommand.c_str());