我试着用谷歌搜索我的问题的答案,但我似乎找不到答案。
下面是我非常简单的测试代码:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(void) {
char ch;
printf("Enter character: ");
ch = getch();
printf("%c", ch);
return 0;
}当我尝试在Eclipse中运行此命令时,我甚至无法获得显示的第一个printf行,并且执行任何按键操作都不起作用。
我还尝试了fflush(stdout)和fflush(stdin),但是程序并没有按照我希望的那样运行。如果我在Visual Studio上尝试这一点,它可以完美地工作。
有人知道为什么吗?谢谢。
发布于 2015-03-28 12:38:43
output, for instance to the console/terminal, is buffered.
it will not actually be output until either:
1) a newline is output.
2) fflush(stdout) is called.
3) a read from stdin is performed
using getchar() will cause the stdout output buffer
to be flushed to the console/terminal.
the final printf() is not showing for this same reason.
suggest changing the format string from "%c" to "%c\n"发布于 2019-05-08 07:26:40
Eclipse控制台窗口似乎不支持键盘输入。
作为解决方法,您可以将调试会话配置为启动外部终端窗口。
在Eclipse-Oxygen上,您可以从Debug Configuration对话框中执行此操作。在[调试器]选项卡中,找到指定
对下级使用外部控制台(打开一个新的控制台窗口进行输入/输出)
在C++中使用cin时也会出现此问题。请看这个问题:c++ debug mode in eclipse causes program to not wait for cin
发布于 2015-03-28 12:36:25
尝试在前面添加以下行以打开控制台:
FILE * a = fopen("CON","w");
freopen("CON","w",stdout);
freopen("CON","r",stdin);
fclose(a);祝好运!
https://stackoverflow.com/questions/29313325
复制相似问题