Simple Question

Hey guys, I'm working on a program, and I'm at a situation where I would like to have the user press "Enter" to continue.

1
2
 cout <<"Press Enter to Continue..."<<endl;
       cin  >> z;


I tried making my input a char, but enter isn't a char, so that didn't work, neither did using a int value (which I knew wouldn't work)

any suggestions?
cin.get()

or you could also try

cin.ignore()
Last edited on
You can use system("pause") for small programs. It is bad practice to use this, but for testing purposes you can use it. I have heard that cin.get() works, but it never has for me.
1
2
3
int x;
cin >> x;
cin.get();


This won't do anything, you would need to put in an extra cin.get()
Why should
system("pause");
be a bad habit ?
Because it is asking the operating system to do something for you. You have no idea what it will do, and no control over that. If you're lucky, the operating system understands the command AND it does what you expect. If you're unlucky, it does something else entirely. If you try it on my PC, it kills the process entirely because that's what I set the pause command to do (which I had to create myself, as the shell I use doesn't have such a command). I could easily change it so that it, for example, deletes the programme or formats the hard drive or eMails your logon details to me.

Additionally, it's very expensive. Read this: http://www.gidnetwork.com/b-61.html

Thanks for the link.
Never knew Pause would be that troublesome?
Probably Im at low level so I couldnt see the differences
i think there is no need for cin object. you may do that by writing:

z=getch();
and check if(z==13){...}. 13 is the ascii code for carriage return
cin is standard, getch is not. Point invalid.
Topic archived. No new replies allowed.