In most cases, using the qx// mechanism is the preferred way of doing this. That said, if you had preferred that the output appear on the terminal for users to see, you could do that by piping the output of your C++ program through "tee":
The "tee" filter copies its STDIN to its STDOUT while making a copy to $capturefile. "tee" is also a useful tool when trying to diagnose complex pipes.