Compilation IO Guide
Compile and Execute C++ Program with Input and Output Redirection
Standard
g++-14 -std=c++17 -Wall -O2 -fno-sanitize-recover -o A A.cpp
Debug
g++-14 -std=c++17 -DDEBUG -Wall -O2 -fno-sanitize-recover -o A A.cpp
Running
./A < A.in > A.out
Explanation
This command compiles and executes a C++ program, redirecting the input and output to specific files. Below is a breakdown of the command: (Useful for competitive programming)
g++-14
: Specifies the version of the GNU C++ Compiler, in this case, version 14.-std=c++17
: Instructs the compiler to use the C++17 standard for compilation.-Wall
: Enables all compiler warnings, which helps in identifying potential issues.-O2
: Activates a moderate level of optimization to improve the performance of the compiled program.-fno-sanitize-recover
: Ensures the program stops execution immediately when encountering a sanitization error, instead of attempting to recover.-DDEBUG
: Defines the macroDEBUG
, enabling any conditional compilation sections related to debugging within the source code.-o A
: Specifies that the output executable file will be namedA
.A.cpp
: The source file to be compiled../A < A.in > A.out
: Executes the compiled program, reading input from the fileA.in
and writing the output to the fileA.out
.
This method is efficient for running programs with predefined input and capturing the output into a file for further analysis or documentation purposes.