View Single Post
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: replacement of getch()

 
0
  #2
Oct 3rd, 2004
>i just want to whether there is a replacement for getch() in C++.
There isn't a standard equivalent for getch in either C or C++.

>my friend said getch() is C function.
No, getch is a compiler extension. You can use it in either C or C++ if your compiler supports it, but for the most part you don't need to.

For what purpose were you intending to use getch? The most common by far is keeping a console window from closing when you run the program from a Windows IDE:
  1. #include <conio.h>
  2.  
  3. int main()
  4. {
  5. // Your program here
  6.  
  7. getch();
  8. }
That's not a recommended solution, and most experienced programmers will recommend that you use cin.get:
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. // Your program here
  6.  
  7. std::cin.get();
  8. }
I'm here to prove you wrong.
Reply With Quote