Skip to content

Instantly share code, notes, and snippets.

@G36maid
Created September 6, 2024 18:05
Show Gist options
  • Select an option

  • Save G36maid/9ea4a76fba9f47a7e79d30e6b2421482 to your computer and use it in GitHub Desktop.

Select an option

Save G36maid/9ea4a76fba9f47a7e79d30e6b2421482 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 <cpp_file> [input_file] [output_file]"
exit 1
fi
cpp_file=$1
input_file=$2
output_file=$3
if [ -z "$input_file" ]; then
input_file="in.txt"
fi
if [ -z "$output_file" ]; then
output_file="out.txt"
fi
g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++11 "$cpp_file" -o "${cpp_file%.*}"
if [ $? -eq 0 ]; then
echo "Compilation successful. Running program..."
./"${cpp_file%.*}" < "$input_file" > "$output_file"
echo "Program execution completed."
rm "${cpp_file%.*}"
echo "Executable file deleted."
else
echo "Compilation failed."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment