The problem is quite common when starting to learn C/C++..
the reason is that console applications once finisher return from their main method, the associated console window automatically closes. This behavior has nothing to do with what your app does or not, or if the app is working well or not.
To "correct" this simple add a pause just before the return statement in the main method
Example:
....
system("pause");
return 0;
}