944,218 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 215892
  • C++ RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Nov 25th, 2008
0

Re: replacement of getch()

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)
Reputation Points: 3
Solved Threads: 0
Newbie Poster
DCX2 is offline Offline
2 posts
since Nov 2008
Jul 21st, 2009
0

Re: replacement of getch()

@ eagle man

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

if u r unaware of standards,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
guru_boy is offline Offline
1 posts
since Oct 2008
Jul 21st, 2009
0

Re: replacement of getch()

@guru_boy:
Click to Expand / Collapse  Quote originally posted by Narue ...
It's generally considered rude to resurrect ancient threads, for any reason.
You didn't bother reading the thread before posting eh?
Moderator
Reputation Points: 3280
Solved Threads: 897
Posting Sage
WaltP is offline Offline
7,753 posts
since May 2006
Aug 17th, 2009
-3

Re: replacement of getch()

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.
Reputation Points: -1
Solved Threads: 0
Newbie Poster
vhortex is offline Offline
1 posts
since Jan 2008
Aug 17th, 2009
-2

Re: replacement of getch()

Click to Expand / Collapse  Quote originally posted by vhortex ...
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.

Quote ...
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".
Reputation Points: 3
Solved Threads: 0
Newbie Poster
DCX2 is offline Offline
2 posts
since Nov 2008
Oct 30th, 2009
1
Re: replacement of getch()
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gobulin is offline Offline
1 posts
since Oct 2009
Oct 30th, 2009
0
Re: replacement of getch()
Click to Expand / Collapse  Quote originally posted by gobulin ...
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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 30th, 2009
0
Re: replacement of getch()
As far as i know getch() is deprecated and it was replaced. TurboC++ users miss getch() a lot.
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
arunpawar is offline Offline
54 posts
since Dec 2007
Dec 27th, 2009
-2
Re: replacement of getch()
Reputation Points: 51
Solved Threads: 14
Junior Poster
ahamed101 is offline Offline
114 posts
since Jul 2008
Jan 11th, 2012
0

Better to post to an old relevant thread than start a new one...

I used google trying to find what is the easy way to implement the ubiquitous "Hit any key to continue." in a "console" app (I'm using Visual Studio 2010 atm).

I found the answer above, thank you DCX2. Here is the 2010 version of the answer:

http://msdn.microsoft.com/en-us/library/58w7c94c.aspx

Microsoft: "Use the ISO C++ conformant _kbhit"

(You have do do something like:
C++ Syntax (Toggle Plain Text)
  1. while( !_kbhit() );
)

[o.t. rant]
Since this thread has already been thoroughly trashed by people more concerned with showing how much smarter they are than the other poster [implicitly bringing themselves down to their level] I must address a particularly irksome point:

> "It's generally considered rude to resurrect ancient threads, for any reason."

NO! To anyone who says that, please stop it already!!!

I have been reading the Internet since about 1987. That general idea about posting to "old" threads being bad has to be one of the most ignorant ones I have run across in twenty five years... Ugh.
[/o.t. rant]
Last edited by critofur; Jan 11th, 2012 at 6:00 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
critofur is offline Offline
1 posts
since Feb 2006
Message:
Previous Thread in C++ Forum Timeline: Exporting Threads How?
Next Thread in C++ Forum Timeline: Minimum value in a 2-d array with strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC