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
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
It ain't illegal until you get caught..
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");
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?Originally Posted by Scribbler
It ain't illegal until you get caught..
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
Last edited by major_small; 02-07-2005 at 05:09 PM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Aha, now I got the terminating character thing, thanks for you too major_small..Originally Posted by major_small
It ain't illegal until you get caught..
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.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
And of course there's portability. pause and cls and many others are meaningless outside of windows.
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?
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
try avoiding having to clear the screenOriginally 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(){...}
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
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.