Why does kbhit() always return 0 when input is entered in the Eclipse console?
I am running Eclipse CDT (Helios) for C/C++ on Windows 7 x64. At first I was having the problem of output not appearing when run in the Eclipse console until the program exited, even though it did while running in a Windows console. I discovered this had to do with buffering on the stdout stream. I was able to disable the buffering with the following:
setvbuf(stdout, N开发者_开发技巧ULL, _IONBF, 0);
But now I cannot figure out why kbhit() always returns 0 even when keys are pressed in the console. I tried disabling buffering on stdin:
setvbuf(stdin, NULL, _IONBF, 0);
But this had no effect. My program is a shell application. I am using kbhit() and getch() to read input, which works when the program is run in a Windows console, but not in the Eclipse console. What am I missing here?
Eclipse implements its console in a way that can not work with the "direct" functions kbhit()
and getch()
.
You can set an option to open a real console in your run and debug configurations.
精彩评论