The Worst?

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
onE of the most discussed topic lately :)
Last edited on
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
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
Topic archived. No new replies allowed.