I have a C++ program in Linux (Ubuntu) which prints very long output in a command terminal.
How can i copy this output from command terminal directly to the .txt file by Linux command?
Your shell does this for you by virtue of output redirection:
$ ./a.out > theoutput.txt
In general you type;
command > file.txt
The greater than symbol > redirects standard out to the file.
stdout and stderr separately: command 1>outFile 2>errFile.