I want to run the programs r1-r4 and n1-n4 simultaneously instead of waiting for each one to finish executing,I've been stuck on this for a long time, i went through multi threading for c++ in dev-cpp and the Win API code is quite complicated. Can somebody provide the code to execute them simultaneously or any other easy way i can implement it.

Thank you.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <conio.h>

using namespace std;
             
int main()
{
    
ifstream od,od2,od3,od4,od5,od6,od7,od8;
ifstream odd,odd2,odd3,odd4,odd5,odd6,odd7,odd8;
string line;
int num[8],nu=0;


system("r1.exe");system("CLS");
system("r2.exe");system("CLS");
system("r3.exe");system("CLS");
system("r4.exe");system("CLS");

system("n1.exe");system("CLS");
system("n2.exe");system("CLS");
system("n3.exe");system("CLS");
system("n4.exe");system("CLS");



od.open("r1.txt");
getline(od,line);
num[nu]=atoi(line.c_str());
nu++;
od.close();

od2.open("r2.txt");
getline(od2,line);
num[nu]=atoi(line.c_str());
nu++;
od2.close();

od3.open("r3.txt");
getline(od3,line);
num[nu]=atoi(line.c_str());
nu++;
od3.close();

od4.open("r4.txt");
getline(od4,line);
num[nu]=atoi(line.c_str());
nu++;
od4.close();

od5.open("n1.txt");
getline(od5,line);
num[nu]=atoi(line.c_str());
nu++;
od5.close();

od6.open("n2.txt");
getline(od6,line);
num[nu]=atoi(line.c_str());
nu++;
od6.close();

od7.open("n3.txt");
getline(od7,line);
num[nu]=atoi(line.c_str());
nu++;
od7.close();

od8.open("n4.txt");
getline(od8,line);
num[nu]=atoi(line.c_str());
nu++;
od8.close();




int best=0;
best=num[0];

for(int i=0;i<nu;i++)
{
if(num[i]>best){best=num[i];}
}


cout << best ;


cin.get();
return 0;
 
}

call win32 api ShellExecute() or CreateProcess() instead of system() to execute another program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.