Alternative Function in iOStream.H for Getch() of Conio.H

c++ alternative for getch() and clrscr()

Try #include <conio.h>

Works fine on my machine (Windows and Linux, mingw compiler for Windows). As I know Code::Blocks uses gcc compiler.

Linux equivalent for conio.h getch()

There are a number of different ways of doing this more portably. The simplest is to use curses:

#include "curses.h"

int main() {
initscr();
addstr("hit a key:");
getch();
return endwin();
}

getch is deprecated

Microsoft decided to mark the name without underscore deprecated, because those names are reserved for the programmer to choose. Implementation specific extensions should use names starting with an underscore in the global namespace if they want to adhere to the C or C++ Standard - or they should mark themselves as a combined Standard compliant environment, such as POSIX/ANSI/ISO C, where such a function then corresponds to one of those Standards.

Read this answer about getcwd() too, for an explanation by P. J. Plauger, who knows stuff very well, of course.

If you are only interested to wait for some keys typed by the user, there really is no reason not to use getchar. But sometimes it's just more practical and convenient to the user to use _getch and friends. However, those are not specified by the C or C++ Standard and will thus limit the portability of your program. Keep that in mind.



Related Topics



Leave a reply



Submit