The Worst?

Jul 27, 2009 at 1:12pm
ive been reading the other post about "Console closing down" and i didnt understand why the system("pause") is the worst... is it because you have to press any key to terminate? here is my code that worked fine in my computer.
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main ()
{
   cout << "Hello world"<<endl<<endl;
   system("pause");
   return 0;
}
Last edited on Jul 27, 2009 at 6:26pm
Jul 27, 2009 at 1:24pm
Jul 27, 2009 at 1:26pm
onE of the most discussed topic lately :)
Last edited on Jul 27, 2009 at 1:34pm
Jul 27, 2009 at 1:27pm
is it because you have to press any key to terminate?
No.

here is my code that worked fine in my computer.
That would be because you are on a windows machine.

The main problem with using it is that:

1. It is OS-dependant, in this case Windows. This basically means that only people in Windows based machines can use your program - it is not portable.
2. There are other methods that are much better. For example std::cin.get() or just cin.get() depending on whether you are using namespace std;

I have a feeling you're getting confused on one thing though. It is not that system("pause") is specifiaclly bad, it is system() in general. Read this for more info: http://www.cplusplus.com/forum/articles/11153/

EDIT** ahh too late :(
Last edited on Jul 27, 2009 at 1:28pm
Jul 27, 2009 at 1:32pm
btw, try to compile such code using e.g. gcc 4.4.0 under Ubuntu 9.04 - won't work without including cstdlib.h - IMHO it is better to use standard solutions <- but that's only a minor reason -> look above
Last edited on Jul 27, 2009 at 1:32pm
Jul 27, 2009 at 1:34pm
Topic archived. No new replies allowed.