How to execute a program by using a C++ program's command?

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Helgso

Helgso
Dec 5, 2005
200
0
0
31
Iceland
www.tv.is
I'm playing around with the C++ language and I got the idea of a program that executes a desired game. It simply gives you a list of games, which you can then choose which you want to run. (Already done so).

Now, I was going to make the program so when you picked a game it would start it automatically but then I hit the end of my knowledge.

The thing is, is there any command you know that would make the C++ program run another program? Example:

Code:
main()
{
      int selection // Tells the program to store information about which game is picked

      cout<<"Select a game to start: \n"; // cout is the command to display messages
      cout<<"\n";
      cout<<"1. Unreal Tournament\n";
      cout<<"2. UT2K4\n";
      cout<<"3. UT3
      cout<<"4. Unreal\n";
      cin>> selection; //Tells the program to store the number 1, 2, 3 or 4 to its memory
      if ( selection == 1 ){
            [b]execute "C:\UnrealTournament\System\UnrealTournament.exe";[/b]
      }

SO, at the bottom where I say "execute" (it is highlighted, and It's not the correct command), I want the program to run Unreal Tournament. IS THIS POSSIBLE? To make the program execute Unreal Tournament? IS C++ BUILT TO BE ABLE TO RUN OTHER PROGRAMS?

HELP HIGHLY APPRICIATED. THANKS!
 

Continuum

Lobotomistician
Jul 24, 2005
1,305
0
0
43
Boise
Quickest way would be the system("path to execute")
There are probably a dozen other ways could be used if that one didn't work.
 

Helgso

Helgso
Dec 5, 2005
200
0
0
31
Iceland
www.tv.is
Quickest way would be the system("path to execute")
There are probably a dozen other ways could be used if that one didn't work.

So it should state?:

system("C:\UnrealTournament\System\UnrealTournament.exe");

I tried it out but then my compiler CodeBlocks said:
Code:
||===  Debug ===|
|35|incomplete universal character name \U|
|35|warning: unknown escape sequence '\S'|
|35|incomplete universal character name \U|

So, it didn't work. Do you know any link to a website that might be able to help me?
 

Helgso

Helgso
Dec 5, 2005
200
0
0
31
Iceland
www.tv.is
YAY!

I got it to work!!

It's not supposed to be:

Code:
system("C:\UnrealTournament\System\UnrealTournament.exe");

It's supposed to be:

Code:
system("C:\\UnrealTournament\\System\\UnrealTournament.exe");

MANY THANKS!
 

Paderburner

New Member
Aug 14, 2010
1
0
0
Hey Helgso,
how did u come to that solution? Do u know, why an additional backslash is necessary?

Its interesting me