Tell me, please. I need to create 2 exe-files: test1.exe and test2.exe. We put in different folders, let the first place in c:\home\test1.exe and the second in c:\work\test2.exe . write two text files:
test1.txt: c:\home\test1.exe c:\work\test2.exe test2.txt: c:\work\test2.exe c:\home\test1.exe then we write the program prog.exe which takes as an argument the path to one of two text files. The results of the work are:
prog.exe test1.txt: запуск сначала test1, затем test2 prog.exe test2.txt: запуск сначала test2, затем test1 The question is how to run .exe files from a read text file?
#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; } 