简体   繁体   English

C++程序编译器用g++命令编译后自动运行exe文件

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

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?为了运行 C++ 程序,我们首先运行“g++ file.cpp”,然后在 CMD 中运行“a.exe”,我们可以在单个命令中完成所有操作吗? If yes, how?如果是,如何?

Use the && :使用&&

g++ file.cpp && a.exe

There is 2 options:有2个选项:

  1. g++ file.cpp &&./a.exe g++ file.cpp &&./a.exe
  2. g++ file.cpp; g++ 文件.cpp; ./a.exe ./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). a)第一个执行您的程序(a.exe),即使编译失败(当然,如果您之前已经编译过您的程序)。

b) The second do not run your program if the compilation failed (even if you have already compiled your program previously). b)如果编译失败,第二个不要运行您的程序(即使您之前已经编译过您的程序)。

So the 2nd option is more correct because you are sure that if the compilation failed you wouldn't run your previously executable.所以第二个选项更正确,因为您确定如果编译失败,您将不会运行以前的可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM