Replacementr Of getch()

Well I've been using Turbo C++ for quite a while. Then after finding out its quite obsolete, i switched to GCC compiler with Code::Blocks IDE. I recently found out that conio.h is not a standard library. Unfortunately I use getch() function quite a lot for preventing echoing the input on the screen and other purposes, which is under conio.h. Can anyone tell me an alternate to getch() with similiar function which falls under a standard library.
Last edited on
I know mingw does have a conio.h header.
As far as I can see in this site's reference, there isn't any such function. I would suggest using curses instead, as they are cross-platform.
Hi.
This is a getch simulation in linux. search for something similar in windows.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int getch()
{
	struct termios oldt, newt;
	int ch;
	tcgetattr(STDIN_FILENO, &oldt);
	newt = oldt;
	newt.c_lflag &= ~( ICANON | ECHO );
	tcsetattr(STDIN_FILENO, TCSANOW, &newt);
	ch = getchar();
	tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
	return ch;
}
Just continue to use getch() and do not worry about being non standard, all modern windows compilers support it. (MinGW and Visual Studio have conio.h header).
Well modoran, I use Code::Blocks IDE with GNU GCC compiler. I wrote the code in it with a few changes though. After building it there is an error saying-
error:'getch' was not declared in this scope.
Also is there strcmpi is not working. It says-
cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'|... Please Help.
well the getch() problem is solved but the strcmpi froblem remains!!
use c_str() function of class string:
1
2
string str = "Hi";
char* charPtr = str.c_str();
Thanks, It worked!
Topic archived. No new replies allowed.