replacement of getch()

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 2
Reputation: DCX2 has a little shameless behaviour in the past 
Solved Threads: 0
DCX2 DCX2 is offline Offline
Newbie Poster

Re: replacement of getch()

 
0
  #21
Nov 25th, 2008
Originally Posted by nomorejunkmail View Post
Found this thread when googling getch, and I had to respond.
Ditto.

getch() is deprecated. Instead, MS recommends you use _getch() (note the underscore) Same with kbhit() - use _kbhit() instead.

Personally, I find _kbhit() more useful, because _getch() will block waiting for input and if I wanted to block I'd use cin instead. _getch() also locks the current thread by default (_kbhit() doesn't need to since it's just peeking at the buffer); there are non-locking versions, e.g. _getch_nolock()

Include conio.h if you wish to compile code with _getch().

Also, make sure you link against the C Runtime (CRT) library. _getch() is a part of the CRT. Typically, the CRT is provided in pre-compiled object form (*.lib) by whoever wrote your compiler (e.g. Microsoft if you're using Visual Studio). It's usually linked in by default, but you may need to instruct your linker to link against the library, typically libcmt.lib or libcmtd.lib. (libcmtd = LIBrary C MultiThreaded Debug)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: guru_boy is an unknown quantity at this point 
Solved Threads: 0
guru_boy guru_boy is offline Offline
Newbie Poster

Re: replacement of getch()

 
0
  #22
Jul 21st, 2009
@ eagle man

refer this document
http://www.open-std.org/JTC1/SC22/wg...docs/n1124.pdf

if u r unaware of standards,
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: replacement of getch()

 
0
  #23
Jul 21st, 2009
@guru_boy:
Originally Posted by Narue View Post
It's generally considered rude to resurrect ancient threads, for any reason.
You didn't bother reading the thread before posting eh?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 1
Reputation: vhortex has a little shameless behaviour in the past 
Solved Threads: 0
vhortex vhortex is offline Offline
Newbie Poster

Re: replacement of getch()

 
-2
  #24
Aug 17th, 2009
on my entire online life, this is the most bizarre thread i found. the thread started Oct 3, 2004.

got an unexpected resurrection 3 years after. and another year it was resurrected with some arrogance and rudeness and on the next year it was resurrected again. can anyone lock this thread and create a new one if the case was not yet solved. it was almost 5 years since the thread was started.

and a side about the compiler and libraries. frankly.. there are a lot of new programmers which cannot differentiate a pseudo code from an actual live source code. let alone to know the difference from extended libraries and extended compiler features.

cya for now.. i'll continue my search for methods to emulate getch.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: DCX2 has a little shameless behaviour in the past 
Solved Threads: 0
DCX2 DCX2 is offline Offline
Newbie Poster

Re: replacement of getch()

 
-1
  #25
Aug 17th, 2009
Originally Posted by vhortex View Post
on my entire online life, this is the most bizarre thread i found. the thread started Oct 3, 2004.
I know it's difficult to comprehend, but sometimes programming languages and their associated APIs evolve. This page was a rather prominent result during my google search for getch and it suggests using deprecated features. To me, it was just common sense to add some information for future googlers who stumble on this thread.

and a side about the compiler and libraries. frankly.. there are a lot of new programmers which cannot differentiate a pseudo code from an actual live source code. let alone to know the difference from extended libraries and extended compiler features.
And maybe some of those new programmers will google terms I used that they do not understand, and maybe they'll even learn enough to stop being "new programmers".
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: gobulin is an unknown quantity at this point 
Solved Threads: 0
gobulin gobulin is offline Offline
Newbie Poster
 
0
  #26
25 Days Ago
I'm looking for a way to grab a single character from the console without the need to hit "ENTER" after each character. I know that getch() has this feature and cin.get() does not. Is there a 'better' method than getch() to grab a single console character without the "ENTER"?

Thank you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #27
25 Days Ago
Originally Posted by gobulin View Post
I'm looking for a way to grab a single character from the console without the need to hit "ENTER" after each character. I know that getch() has this feature and cin.get() does not. Is there a 'better' method than getch() to grab a single console character without the "ENTER"?

Thank you.
If it works, it works.

There's no point worrying about if a better methods exists because getch() or anything that simulates its behaviour is going to be non-standard anyway, so your concern is a moot point.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 44
Reputation: arunpawar is an unknown quantity at this point 
Solved Threads: 0
arunpawar arunpawar is offline Offline
Light Poster
 
0
  #28
25 Days Ago
As far as i know getch() is deprecated and it was replaced. TurboC++ users miss getch() a lot.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC