C++ program compiler run the exe file automatically after compiling with g++ command

3.1k views Asked by At

For running C++ program we first run "g++ file.cpp" and then we run "a.exe" in CMD Can we do it all in single command? If yes, how?

2

There are 2 answers

2
HolyBlackCat On BEST ANSWER

Use the &&:

g++ file.cpp && a.exe
0
Patapoom On

There is 2 options:

  1. g++ file.cpp && ./a.exe
  2. g++ file.cpp ; ./a.exe

a) The first one execute your program (a.exe) even if the compilation failed (if you have already compiled your program previously of course).

b) The second do not run your program if the compilation failed (even if you have already compiled your program previously).

So the 2nd option is more correct because you are sure that if the compilation failed you wouldn't run your previously executable.