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
Implicit Conversion from Char** to Const Char**
Concat Two 'Const Char' String Literals
Blur Effect Over a Qwidget in Qt
<Iostream> VS. <Iostream.H> VS. "Iostream.H"
Cmake Linking Against Shared Library on Windows: Error About Not Finding .Lib File
Ncurses and Qt Interoperability
Code Runs Perfect in G++ But Not in Xcode - Cannot Find File
Is the Data in Nested Std::Arrays Guaranteed to Be Contiguous
How Do We Explain the Result of the Expression (++X)+(++X)+(++X)
What Is the Purpose and Return Type of the _Builtin_Offsetof Operator
2D-Array as Argument to Function
C++/C Function Pointers That Return Void*
Virtual Destructor and Undefined Behavior
Standard Conversions: Array-To-Pointer Conversion