Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: azrael2000 on November 18, 2010, 06:24:57 pm
-
Hi All.
Just a little question.
While developing, I normally use the command
in C++ to stop the console window so I can see what is in it.
I have tried this command in Code::Blocks and it fails.
Do I have to load a .h file? In other programs I have used this has never been an issue.
I am running windows 7 OS
Regards
-
The first thing:
C::B is an IDE not a compiler, it can work with many compilers.
If you use a project (recommended), you should go to "Project -> Properties -> Build targets", make sure your target is of type "Console project" and you have checked "Pause when execution ends".
-
The standard doesn't contain "system", and it's not portable.
You can try to use "cin.get()" to pause the execution.
-
Hi there.
Thank you for the response.
I checked where you suggested, and I do have the check box checked.
However, the console window still just quickly flashes when the compiled program (debug or release) runs and then is no more.
I've been using the gcc compiler with the program.
Regards
-
Hi there.
Thank you for the response.
I checked where you suggested, and I do have the check box checked.
However, the console window still just quickly flashes when the compiled program (debug or release) runs and then is no more.
I've been using the gcc compiler with the program.
Regards
It works only, if you start your program from inside C::B with the green triangle or via "Build -> Run" (Ctrl + F10) or "Build -> Build and run" (F9), not if you use the debugger and not if you run it from outside C::B.
-
You Must include Windows header file to do that.. <windows.h>
so include this,
#include <windows.h>
Hope this helps..... :) :) :) :) :) :) :) :) :) :) :)
JV net works..
-
> The standard doesn't contain "system", and it's not portable.
system() is part of both the C and C++ standards, which declare it in stdlib.h (or cstdlib).
-
You can try to use "cin.get()" to pause the execution.
To use cin.get() to pause execution, you might have to call cin.sync() first.
> The standard doesn't contain "system", and it's not portable.
system() is part of both the C and C++ standards, which must declare it in stdlib.h (or cstdlib).
I think it is more that the "Pause" that system() is calling is an executable that must exist in the current path; it may or may not exist/function in the same manor - depending on where the program is run - (or could possible be a virus hoping that you will run it by mistake!). (It is also misuse of system(), as forcing the OS to search through the path and load a new program just to pause execution, is a huge amount of overhead to achieve a very tiny function.)