Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: azrael2000 on November 18, 2010, 06:24:57 pm

Title: system("pause") command
Post by: azrael2000 on November 18, 2010, 06:24:57 pm
Hi All.

Just a little question.

While developing, I normally use the command

Code
system("Pause");

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
Title: Re: system("pause") command
Post by: Jenna on November 18, 2010, 06:33:08 pm
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".
Title: Re: system("pause") command
Post by: xunxun on November 18, 2010, 06:40:19 pm
The standard doesn't contain "system", and it's not portable.
You can try to use "cin.get()" to pause the execution.
Title: Re: system("pause") command
Post by: azrael2000 on November 18, 2010, 06:42:31 pm
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
Title: Re: system("pause") command
Post by: Jenna on November 18, 2010, 08:31:19 pm
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.
Title: Re: system("pause") command
Post by: jvnetsl on November 25, 2011, 11:31:15 am
You Must include Windows header file to do that.. <windows.h>
so include this,
#include <windows.h>

Hope this helps..... :) :) :) :) :) :) :) :) :) :) :)

JV net works..
Title: Re: system("pause") command
Post by: zabzonk on November 25, 2011, 12:42:01 pm
> 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).
Title: Re: system("pause") command
Post by: Alpha on November 25, 2011, 04:00:14 pm
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.)