cin.get() VS. system("pause")

So, here's the big deal...

I have both Code::Blocks and Dev-C++
I use them alternatively, and it's been doing fine.

Okay, here's the main question:

Which is better to use... cin.get(); or system("pause");?

cin.get() is good because it doesn't show messages like Press any key to continue... But sometimes, even if I put the code there, it just simply closes the program.

system("pause") on the other hand, even though it shows that annoying message, works always. But it gets ugly if I use this.


Does anyone know why cin.get() sometimes doesn't work?
Does anyone know why cin.get() sometimes doesn't work?


You are leaving junk in the input buffer. Usually it's because you used something like:

std::cin >> x; //where x is an int or whatever

This will leave extra stuff in the input buffer, usually a '\n' or possibly other stuff.
I believe the proper way to use cin is as follows:
1
2
std::cin >> x;
cin.ignore();

I don't use cin much, if at all, and when I do, Code::Blocks has a feature that you don't need system("pause"); or cin.get(); at the end of the program, it pauses it for you with information about your code.

I also don't understand why you still use Dev-C++ I believe it hasn't been updated for over 5 years now.
Well, I still use Dev-C++ because it's more user-friendly.
Than code blocks? How so?
I dunno, i just find Dev-C++ easier...
But then, okay, if you like, I'll just use Code::Blocks

I use Dev-C++ because it's the compiler that I grew up with. :/
I don't want to force you to do something you don't want to do, and I personally grew up with BloodShed and Borland. For all I care, you can use no IDE's at all. I've gone through a good bit of the bigger ones and I'm content with Code::Blocks, it just needs an update, I might try a nightly build from the forums.
The Code::Blocks console runner automatically give you the return value, time it took to run and pauses when you run the project from withing the IDE. I love this feature.
To clarify... are you using Bloodshed Dev-C++ or Orwell Dev-C++?

-Albatross
Which is better to use... cin.get(); or system("pause");?
None, run from the console.

Why system() is evil http://www.cplusplus.com/forum/articles/11153/
Keep the console open long enough to see your program's output http://www.cplusplus.com/forum/articles/7312/
Topic archived. No new replies allowed.