How to pipe output to less instead of cout?

Feb 2, 2017 at 8:07pm
I wrote a C++ program the generates and displays a summary to cout.
The summary is long and it is inconvenient to scroll and find the top of the summary in the terminal.
Currently I pipe the output to less:
 
 $ ./print_test_case_summary | less

Is there a way a C++ program can pipe output to less instead of cout? e.g.
 
    cless << "Summary";

Or maybe using system() e.g.
 
    system("less");

I don't want to generate a file unless it is automatically deleted when less is closed.

Thank you.
Last edited on Feb 2, 2017 at 8:09pm
Feb 2, 2017 at 10:06pm
What is wrong in piping? The user can let the stream flow, pipe it to some command (like 'less') or redirect it to a file as they please.

Keep your program simple.
Feb 2, 2017 at 10:40pm
That's good advice keskiverto.

I should have asked "is there a SIMPLE way for C++ to pipe output to less instead of cout?"
Feb 2, 2017 at 11:36pm
You could do it, but then what if someone wants to send the output of the program to a file? It's better by far to type the extra 5 characters to pipe it to less.
Feb 3, 2017 at 3:18am
I haven't thought of that. I will output to cout.
Thanks dhayden.
Topic archived. No new replies allowed.