How to pipe output to less instead of cout?

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
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.
That's good advice keskiverto.

I should have asked "is there a SIMPLE way for C++ to pipe output to less instead of cout?"
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.
I haven't thought of that. I will output to cout.
Thanks dhayden.
Topic archived. No new replies allowed.