Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c++;节目? 我想在我的C++程序中使用一个exe文件(转换.exe)。此“exe”文件将我的输出文件格式更改为其他格式。当我从命令提示符(cmd)使用这个convert.exe时,我必须这样键入_C++ - Fatal编程技术网

如何在c++;节目? 我想在我的C++程序中使用一个exe文件(转换.exe)。此“exe”文件将我的输出文件格式更改为其他格式。当我从命令提示符(cmd)使用这个convert.exe时,我必须这样键入

如何在c++;节目? 我想在我的C++程序中使用一个exe文件(转换.exe)。此“exe”文件将我的输出文件格式更改为其他格式。当我从命令提示符(cmd)使用这个convert.exe时,我必须这样键入,c++,C++,convert-in-myfile-out convertedfile-n-e-h 在哪里 文件名,我从C++程序中获取 convertedfile=“convert.exe”文件的结果 -n、 -e,-h=是一些参数(列),我需要使用它们来获取我的 所需的数据列 我尝试使用系统(convert.exe)。但是,它不起作用,因为我不知道如何使用所有这些参数。看看: ShellExecute(NULL,“open”、“\convert.exe”, “-in-myfile-out-converted

convert-in-myfile-out convertedfile-n-e-h

在哪里

<文件>文件名,我从C++程序中获取 convertedfile=“convert.exe”文件的结果 -n、 -e,-h=是一些参数(列),我需要使用它们来获取我的 所需的数据列

我尝试使用系统(convert.exe)。但是,它不起作用,因为我不知道如何使用所有这些参数。

看看:

ShellExecute(NULL,“open”、“\convert.exe”,
“-in-myfile-out-convertedfile-n-e-h”,
零,开关(正常);
您可以使用Win32 API。

该函数需要一个
常量字符*
,那么您试试怎么样

system(“convert-in-myfile-out-convertedfile-n-e-h”)

然后,如果希望更灵活一些,可以使用创建一个包含正确元素的字符串,然后将其传递给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);
使用其中一种:

int execl(char * pathname, char * arg0, arg1, ..., argn, NULL);
int execle(char * pathname, char * arg0, arg1,..., argn, NULL, char ** envp);
int execlp(char * pathname, char * arg0, arg1,..., argn, NULL);
int execlpe(char *  pathname, char * arg0, arg1,..., argn, NULL, char ** envp);int execv(char * pathname, char * argv[]);
int execve(char * pathname, char * argv[], char ** envp);
int execvp(char * pathname, char * argv[]);
int execvpe(char * pathname, char * argv[],char ** envp);
系统(命令);来自stdlib.h


既然你不想并行执行,那么系统的(三)连续调用对你来说是不是有作用?

当问题是关于C++时,为什么它有一个C标签?对不起,我想得到更多的评论。试图通过错误地标记问题来吸引注意力是不可接受的。在页面中添加一个链接来描述每个函数的功能会很有帮助。我知道谷歌有帮助,但我还是可以修改这个函数,得到不同的输入文件名,然后得到不同的输出文件,比如(char*infle)谢谢。它起作用了。如何修改此代码以链接任何文件,如(char*filename),然后我可以使用它,或者在需要转换输出时调用它是否定义为函数。任何帮助都可以。@g_niro,我编辑了我的答案,添加了一个示例代码,希望帮助样本在这里溢出。如果文件名的长度足以使结果大于命令缓冲区,sprintf将很高兴地使缓冲区溢出。在构图中使用一些更安全的方法,比如连接std::strings。@SebastianRedl非常同意您的观点,但我认为最好是提供一种易于开始的方法。考虑到这个问题的表述方式,听起来他/她是一个非常新的编程专家。。。每个人都应该知道sprintf的功能,即使使用起来有风险
int execl(char * pathname, char * arg0, arg1, ..., argn, NULL);
int execle(char * pathname, char * arg0, arg1,..., argn, NULL, char ** envp);
int execlp(char * pathname, char * arg0, arg1,..., argn, NULL);
int execlpe(char *  pathname, char * arg0, arg1,..., argn, NULL, char ** envp);int execv(char * pathname, char * argv[]);
int execve(char * pathname, char * argv[], char ** envp);
int execvp(char * pathname, char * argv[]);
int execvpe(char * pathname, char * argv[],char ** envp);