By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Can't remeber...

P: 1
Hi
I am probaly a newbie compared to all you first class C++ programmers so I'm asking you the question.
I remeber reading in a book somewhere a line of code you put right at the end of your file (.cpp or .h etc) that stop your program from closing until you press enter or a key like that, I can't remeber whether it was both or just enter.
So does anyone out there know that code and would be willing to share it with me?
Thankyou
Feb 21 '07 #1
Share this Question
Share on Google+
6 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Hi
I am probaly a newbie compared to all you first class C++ programmers so I'm asking you the question.
I remeber reading in a book somewhere a line of code you put right at the end of your file (.cpp or .h etc) that stop your program from closing until you press enter or a key like that, I can't remeber whether it was both or just enter.
So does anyone out there know that code and would be willing to share it with me?
Thankyou
char a;
cin >> a;

There is another tool that can be used, but many consider it depricated and horribly unweildly.
Feb 21 '07 #2

RedSon
Expert 5K+
P: 5,000
isn't there like a getch(); method or something?
Feb 21 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
isn't there like a getch(); method or something?
@#$%^&*(*^%$#@$%^&*!

Sorry. I hate 'getch()'. conio.h is not considered standard, and will not work on all systems. I hate getch().

That I know of there is 'system(pause)' (that's the approximate command), but that is considered unweildly and bad practice because it will perform the same function as cin in this case, but does so by making a system call to the kernel.

http://www.gidnetwork.com/b-61.html
Feb 21 '07 #4

RedSon
Expert 5K+
P: 5,000
Ahhh oops! Maybe I should moderate myself!
Feb 21 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
Ahhh oops! Maybe I should moderate myself!
Sorry, I feel rather strongly about it. There is definitely a lot of it coming into this forum (so much that I have given up trying to get people to move away from it), and I have seen it several other places as well, but I can't run or compile it.

It's a legitimate method... as long as everyone the executable goes to has the proper conio.h.
Feb 21 '07 #6

Ganon11
Expert 2.5K+
P: 3,652
I use the

Expand|Select|Wrap|Line Numbers
  1. system("PAUSE");
approach, but I'm pretty sure it's platform-dependent. Any of these methods will work, it just depends on which one you pick.
Feb 21 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.