This is an issue which pops up every year that unfortunately the younger students just don't get, primarily because they grew up on Windows.
There are two types of applications that you can create, a console application and a GUI application. If you grew up with Windows or MAC or something similar with windows and buttons, etc. , you'll all be familiar with the GUI apps. The console apps are a much older invention and are usually only used these days for background programs or administrator tools. They are controlled though a text-based console window. In Windows, you access the console by clicking on START -> Run, and then typing "cmd".
All the applications you will create in COS111, COS112, and unless changed COS211 will be console apps. This is because you still need to learn the basics of programming and GUI apps are a lot more complicated when compared to console apps.
GUI apps run an infinite loop to collect event messages from the operating system while console apps just run from start to finish. Once the main() function is exited, all applications close down.
In Windows, if you run a console app by typing in the program name at the command console (ie by running "cmd"
, control will be passed to your app and when it exits, you'll be dropped back into the command console. If you run a console app by double-clicking on it's icon like any other application, Windows will create a console session, run you app inside it and then close the console when your app finishes. If you app runs extremely fast and exits very soon after it's started, you'll barely be able to see what's going on because Windows will have closed the console window before you can read anything. This is the "flashing" every first-year experiences.
There are three ways to make the flashing stop:
1. If you are creating you program from inside an IDE, the IDE itself will usually have an option to allow the window to stay open after the app has exited. I've found by observing others complaints that various IDEs don't seem to support this very well, or else it's hidden away somewhere that beginners can't seem to find it or they don't read the instructions completely.
2. You could add extra code to the end of your program to effectively pause your app. As far as I remember, the lecturers don't mind if you do this but just confirm (send an email to
cos111@osprey.unisa.ac.za), they might have changed their minds.
Language: C++
int main(int argc, char **argv) {
// Your application-specific code goes in here
// pause the application to prevent immediate exit back to the console
cout << "Press enter to exit ..." << endl;
int dummyInt;
cin >> dummyInt;
return 0;
}
3. You could execute your app the way it was designed, from the console itself. If you open a console window by running "cmd", navigate to your application and execute it, when it exits, you'll be returned to the command prompt. The console window won't close down.
I know this reply doesn't answer your question directly but I hope you can use the information I've given.