C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-02-2009, 02:40 PM   #1
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
getch() equivalent in C++

I'm not quite good with C++'s standard library, I need help. Is there a function which will behave like getch() (yes, I know it's not C's standard either), that is, return after exactly one character typed into the standard input stream? I tried cin.get(char&) and int cin.get() but it didn't work. I searched, too, but it proved useless.
__________________
I reinvent the wheel to understand how it works.

Platform:
Windows XP SP2 Professional Edition
Compiler: GCC 4.3.0
Editor: Notepad++ 5.4.2
Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin.

--Quotes--
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
hauzer is offline   Reply With Quote
Old 06-02-2009, 03:14 PM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
There is no standard way defined. You have to use non-standard extensions, which would depend on what OS/Compiler/Run-Time Library you are using how you achieve that. I expect that there isn't a way to (trivially) do that with cin - you'd have to use system specific code (such as include <conio.h> and use getch() if that exists in your implementation).

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 06-02-2009, 03:43 PM   #3
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
As matsp said, there is nothing in the standard library to help you, but you can call getch() in C++ just as easily as you can in C.
bithub is offline   Reply With Quote
Old 06-02-2009, 05:54 PM   #4
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
So I thought.. Thanks!
__________________
I reinvent the wheel to understand how it works.

Platform:
Windows XP SP2 Professional Edition
Compiler: GCC 4.3.0
Editor: Notepad++ 5.4.2
Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin.

--Quotes--
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
hauzer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent to getch in c++ Elkvis C++ Programming 1 02-05-2009 01:07 PM
Another syntax error caldeira C Programming 31 09-05-2008 01:01 AM
kbhit() and getch() Equivalent.. ThLstN C Programming 1 03-11-2008 02:44 AM
Pls repair my basketball program death_messiah12 C++ Programming 10 12-11-2006 05:15 AM
FAQ: Is there a getch() (from conio) equivalent on Linux/UNIX? kermi3 FAQ Board 0 11-01-2002 11:56 AM


All times are GMT -6. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22