我试图在一些基于命令行参数的C++代码中创建一个目录。mkdir在C++系统调用中失败 - int类型的参数与类型为const的参数不兼容char *
命令行参数是一个数字(1,2,3等),我想使一个文件夹是“输出1”,“输出2”等的程序中的每一个呼叫只得到1号和品牌1文件夹。
在主,我有:
string folder = "0";
if (argc == 2)
folder = argv[1];
RunSimulation(c, 0, folder);
然后:
void RunSimulation(Combo c, int it, string folder){
//Create a directory for the files based on the command line args
stringstream fileName;
fileName << "/work/jcamer7/HallSim/Output" << folder;
system(mkdir(fileName.str().c_str()));
我收到此错误:
error: argument of type "int" is incompatible with parameter of type "const char *" system(mkdir(fileName.str().c_str()));
我传递中的参数显然是一个字符串,所以我有点困惑。我是否获得了命令行参数?不知道..
在此先感谢。 詹娜
您是否阅读过['mkdir'手册页](http://man7.org/linux/man-pages/man2/mkdir.2.html)?你知道这个功能实际上做了什么吗? ['system'](http://man7.org/linux/man-pages/man3/system.3.html)函数的作用是什么?提示:错误是* not * from'mkdir'函数调用。 –