When I compile it all works fine, but when I try to run my programsthe output screen only flashes and goes away. I've done all the trouble shooting, including typing the "system ("pause"" statement just before the return statement, but still I get the same effect. Anybobdy with some bright ideas?
Registered: 14 years ago
You need to understand that so far, we've only created console programmes. What this means is that you are supposed to type in the programme name at a console (e.g. DOS command window), the programme will run and when finished, the control passes back to the command prompt.
The problem you're getting is not really an error but rather an annoyance. What happens is that when you run the programme, Windows recognises that it is a console programme so it opens a console window (The one with the black background and the white text). Then your programme starts executing the code in main() . If you've written your programme in the normal way, execution will eventually reach the return 0; statement. When this happens, your programme exits and control returns to Windows.
Since there is nothing more for the console to do, Windows closes it down. If your programme is very short (most likely all of them this year), the time between starting your programme and it finishing is so short that the window just flashes by, as you've noticed.
There are several ways to get around this, one of which is to use the pausing thing you mentioned. Another is to just have the programme wait for you to enter some arbitrary text:
char ch; cin >> ch;
These are all just hacks though. Since the programme is meant to run under a console environment, the most obvious thing to do is actually run it in a console window. Opening up the command prompt usually starts you off in the Windows directory or your home directory. Just navigate to your directory where the executable is, using the change directory command (cd) and then type in the programme name. e.g. If I want to run the Hello World programme and all my programmes are in the C:\unisa\cos211 directory, the following will be in the console window.
I know this looks like too much work to get a simple programme to run but what do you expect? We're writing simple console programmes. Don't expect them to be like ordinary GUI Windows programmes.
Registered: 14 years ago
Another issue regarding the dev C++ compiler is storing your program files in folders where the name of the folder contains a space.For example storing your files in the My documents folder could cause the problem of the console window disappearing.