To run the compiled C++ program with input from a text file and store the output in another text file, follow these steps:
-
Compile the C++ file:
g++ <path_to_cpp_file> -o <output_executable_name>
Example:
g++ ./codeforces_sol.cpp -o ./codeforces_sol
-
Run the program with input and output redirection:
<output_executable_name> < <path_to_input_file> > <path_to_output_file>
Example:
./codeforces_sol < ./input.txt > ./output.txt
This will run the program with input.txt as the input file and save the output to output.txt.