I believe you are referring to a feature of the terminal where a program can use a "alternate" terminal screen for its output and then reset the terminal to the "main" screen when it exits. To do that your program would have to output the character sequences that tell the terminal to do the window switching.
I wrote this test program and it works in my environment where TERM=xterm:
#include <iostream>
#include <unistd.h>
int main(int argc, char *argv[])
{
// switch the terminal to its alternate screen
std::cout << "\033[?1049h";
for(int i = 0; i < 15; ++i)
std::cout << i + 1 << ": line of text" << std::endl;
sleep(3);
// switch the terminal back to its main screen
std::cout << "\033[?1049l";
return 0;
}
This program should switch to the alternate screen, output some (useless) lines of text and then switch the terminal back to its main screen just before exiting. This may or may not work in your environment but give it a try. If it works you can use the same technique in your own program.