This is a common question when people start developing in C++ when working on programs, especially when they are working in Windows. What happens is that you find a sample program, get it compiled, and try to run it and a window flashes up, and instantly closes again. This is because the program being run is for the command-line, and the command-line editor will only be opened while the program is running.
Really, there isn't a problem with how this works; it's a feature of the OS (Operating System), and allows scripts and installers to run without bogging the user down with a command-line interface. The simple, best way to resolve it is to open a console window, and call your program from the command prompt. By working with it this way, you won't run the risk of a program going out live with an unneeded pause at the end (after all, it's extra work for the user too).
There are a couple of OS specific ways to hold the window open, but the ANSI standard method is to use this:
// pause until the user presses enter
std::cin.ignore ( std::numeric_limits::max(), '\n' );
std::cin.get();
The advantage of this method is that it will work in any OS, as it's not a specific API or OS specific function call.