如何在c ++程序中调用.exe文件? [英] how to call .exe file within c++ program?
问题描述
我想在我的C ++程序中使用一个exe文件(convert.exe)。这个exe文件将我的输出文件格式更改为另一种格式。当我使用这个convert.exe从我的命令提示符(cmd),我必须键入这样;
I want to use a exe file (convert.exe), inside my C++ program. This "exe" file change my output file format to another format. when, i use this convert.exe from my command-prompt (cmd), i have to type like this;
convert -in myfile -out转换文件-n -e -h
convert -in myfile -out convertedfile -n -e -h
其中;
myfile =文件名,我从我的c ++程序获得
convertedfile =convert.exe文件的结果
-n,-e,-h =一些参数(列),我需要使用它来获得输出文件与我的
所需的数据列。
myfile= name of the file, I obtain from my c++ program convertedfile= result of the "convert.exe" file -n, -e, -h = are some parameters (columns) that i need to use to get output file with my desired data columns.
我试过系统(convert.exe)。但是,它不工作,因为我不知道如何使用所有这些参数。
i tried with system(convert.exe). but, it does not work as i did not know how to use all those parameters.
推荐答案
std :: system
函数期望一个 const char *
,那么你如何尝试
out convertedfile -n -e -h)
然后,如果想要更灵活一些,可以使用 std :: sprintf
可以创建一个包含正确元素的字符串,然后将它传递给system()函数,如下所示:
Then, if you want to be a little more flexible, you use std::sprintf
can create a string with the right elements in it and then pass it to the system() function like so:
// 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);
这篇关于如何在c ++程序中调用.exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!