Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.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+;_C++_Windows_Exe - Fatal编程技术网

C++ 在采用路径C+之后运行.exe+;

C++ 在采用路径C+之后运行.exe+;,c++,windows,exe,C++,Windows,Exe,你能帮我吗?我需要运行文件类型为.exe。我有两个test1.txt和test2.txt文件,在这些文件中有两个路径指向pr1.exe和pr2.exe。但是在我运行的第一个txt文件中,pr1.exe和pr2.exe,在另一个txt文件中有pr2.exe和pr1.exe #include <iostream> #include <fstream> #include <process.h> using namespace std; int main(int a

你能帮我吗?我需要运行文件类型为
.exe
。我有两个
test1.txt
test2.txt
文件,在这些文件中有两个路径指向pr1.exepr2.exe。但是在我运行的第一个txt文件中,pr1.exepr2.exe,在另一个txt文件中有pr2.exepr1.exe

#include <iostream>
#include <fstream>
#include <process.h>

using namespace std;
int main(int argc, char *argv[]) {

    cout << "argc = " << argc << endl;
    for (int i = 0; i < argc; i++) {
        cout << "Argument: " << i << " = " << argv[i] << endl;
    }

    if (argc != 2) {
        cout << "Error" << endl;
        exit(-1);
    }
    char ch;
    ifstream infile;
    infile.open(argv[1]);
    if (!infile) {
        cout << "errrrror: cant open a file" << argv[1];
        exit(-1);
    }
    while (infile) {
        infile.get(ch);
        cout << ch;
    }
    cout << endl;
    system("pause");

    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(int argc,char*argv[]){

您需要的是
CreateProcess
函数,更多信息请访问:


注意:如果你的程序没有发送任何命令行参数,你也可以交换第一个和第二个参数。

你能帮我建立它吗?如何建立它?它的代码在问题中。我将编辑它以包括
windows.h
,但这就是你真正需要的
    // start the program up
    #include "windows.h"

    std::wstring("pr1.exe");
    STARTUPINFO si;     
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    if(!CreateProcess(NULL, (LPWSTR)wstr.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
    {
           //error
    }

    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );