If the top and bottom are fixed, it can be something like:
cat top.txt /dev/stdin bottom.txt > text.txt 
# with cat, - works the same as /dev/stdin
or
{ 
  echo 123 #top.txt
  cat
  echo 456 #bottom.txt
} > text.txt 
followed by your compilation commands
cat top.txt /dev/stdin bottom.txt > text.txt
gcc whatever 
The first line should be a shebang line specifying your interpreter, unless you're OK with /bin/sh
 #!/bin/bash
 cat top.txt /dev/stdin bottom.txt > text.txt
 gcc whatever
If you then mark the script executable with chmod +x the_script,
./the_script will be equivalent to /bin/bash ./the_script.
If you want the scrip to abort a command fails, start it with set -e (or make the shebang line (#!/bin/bash -e).
 
                