我想在我的C++程序中使用exe文件(convert.exe).这个"exe"文件将我的输出文件格式更改为另一种格式.什么时候,我从命令提示符(cmd)使用这个convert.exe,我必须这样输入;
转换-in myfile -out convertedfile -n -e -h
哪里;
myfile =文件的名称,我从我的c ++程序中获得convertfile ="convert.exe"文件的结果-n,-e,-h =是我需要用来获取输出文件的一些参数(列)所需的数据列.
我尝试使用system(convert.exe).但是,它不起作用,因为我不知道如何使用所有这些参数.
dm7*_*m76 14
该std::system功能需要a const char *,所以你试试怎么样
system("convert -in myfile -out convertedfile -n -e -h")
然后,如果你想要更灵活一点,你std::sprintf可以创建一个包含正确元素的字符串,然后将它传递给system()函数,如下所示:
// create a string, i.e. an array of 50 char
char command[50];
// this will 'fill' the string command with the right stuff,
// assuming myFile and convertedFile are strings themselves
sprintf (command, "convert -in %s -out %s -n -e -h", myFile, convertedFile);
// system call
system(command);
Run Code Online (Sandbox Code Playgroud)