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?
C++ program compiler run the exe file automatically after compiling with g++ command
3.1k views Asked by IROC At
2
There are 2 answers
0
On
There is 2 options:
- g++ file.cpp && ./a.exe
- 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.
Use the
&&: