It's doing what it's designed to do,
1. Open
2. Run
3. Close
So, you can either input a getline or cin call at the end of the program, use a pause function, or run it from the command line yourself. Any of those solutions will get you the desired result.