g++ main.cpp
compiles it, the compiled program is then called 'a.out' (g++'s default output name). But why are you getting the output of the compiler?I think what you want to do is something like this:
#! /bin/bash# Compile to a.outg++ main.cpp -o a.out# Then run the program with input.txt redirected# to stdin and the stdout redirected to output.txt./a.out < input.txt > output.txt
Also as Lee Avital
suggested to properly pipe an input from the file:
cat input.txt | ./a.out > output.txt
The first just redirects, not technically piping. You may like to read David Oneill
's explanation here: https://askubuntu.com/questions/172982/what-is-the-difference-between-redirection-and-pipe