About Dev-C++

Every time I run my codes to show the output(using command prompt), it only shows for about half a second on the screen. I've done some research about this problem and found the code: system ("pause")
That's why I have to type it for ALL my source codes to show the result normally on the screen. My question is--Is it just my compiler(Dev-C++), or I need to configure something?
Most compilers are like that (maybe all compilers?).

I'd recommend that you use cin.get() instead of system().

Spend enough time on this forum and you will learn that system() is as evil as can get.

We... don't like system() here. We much prefer
1
2
#include <limits>
cin.ignore(numeric_limits<streamsize>::max(), '\n');


It's verbose, but it's better.

And no, you need configure nothing, though I'm sure there is an option to keep the console open while debugging.

-Albatross
It's how your compiler/debugger works.

There might be an option that lets you do that. You could also just run it from the command line yourself.

EDIT: Wow, triple post >_>
Last edited on
cin.ignore(std::numeric_limits<streamsize>::max(), '\n');

Buddy, you're just going to have to get used to it. Not being jerky, just truthful.

Although Codeblocks does automatically pause it, that's only if you run from the compiler. If you run the program alone, no pause.
Note that with the suggested code here you will not be prompted by the consule to "Press Any Key To Continue" also you have to press "Enter" to move on unless you set the first argument to 1.
Hey firedraco Im not having triple post anymore >_>
Thanks for recommending cin.get() But I dont get why you all treat system() as evil worse. And an additional question- If both of those two have the same function and results, why is there a better one?
Last edited on
Ok. I find out that using system() can cause some security problems, and its pretty slow. There are trully many reasonable ideas behind using cin.get. As a beginner in C++, I'm slightly disappointed for using system() for almost 3 days, thats why I decided to use a better one.
But then again, as is explained in the stickied thread here in the beginner forums, there is usually no harm in using it when just learning to program, without releasing the code you're writing. But still, it's good practice to find other ways than system().
Topic archived. No new replies allowed.