I use cin.get() for the program not to exit unles the user presses the return key, but it does not work all the time, sometimes the program exits without the user pressing the return key. Why is that?
Thank you,
Amy
Printable View
I use cin.get() for the program not to exit unles the user presses the return key, but it does not work all the time, sometimes the program exits without the user pressing the return key. Why is that?
Thank you,
Amy
cin.get(); may be reading something already in the input buffer, not allowing the user to press enter. Try
instead. Or you could just add another cin.get(); after the first.Code:system("PAUSE");
Thank You :)
Many/most compilers have a Debug option for executing your compiled program instead of just selecting Run. This will provide you with an opportunity to also see the Exit status of your program upon completion, and a prompt to press enter. (I'm assuming that you are having the problem that your program opens a window then closes before you can see the results)
Yes I do debug it to see it, but the problem is not about me seeing the result program, I do not want the exe file to exit itself once it is done with all operations, and I sometimes do not want to add an option at the end of my program like "If you want to quit press *", so I was using cin.get() expecting the user to hit the return key before the program ends, but why isn't it working all the time?Quote:
Originally Posted by Scribbler
avoid using system calls when possible - check out my tip here (you probably used cin somewhere in your code): http://www.cprogramming.com/tips/sho...ount=30&page=0
Aha, now I got the terminating character thing, thanks for you too major_small..Quote:
Originally Posted by major_small
What's wrong with using system calls?
security issues mostly. say I get onto your computer and replace the pause.exe with a pause.exe that I wrote. now every program you wrote runs my program, which will be completely transparent to you because I have it spawn off a keylogger and then pause your thread so you never knew anything ever went wrong.
now I have your credit card, social security number, passwords, girlfriend's name, anything I could possibly want from you. ;)
And of course there's portability. pause and cls and many others are meaningless outside of windows.
Yes, I realized that already.
How else can you clear the screen without system("cls")?
Now doesn't this sound like it would be a Fequently Asked Question to you?
try avoiding having to clear the screen ;)Quote:
Originally Posted by Junior89
the answer: there is no standard way. the way I do it is like this:
that way with one quick edit to your code, you can switch that to work in windows...Code:void clearScreen() { system("clear"); }
int main(){...}
If you want to clear the screen and avoid using system calls, you can include the conio.h libraries for windows, or the ncurses libraries for *nix.