在 Eclipse 中运行时C++程序的输入提示不出现
Input prompt for C++ program doesn't appear when running in Eclipse
我开始用c++进行桌面编程,当我运行以下代码时:
#include <stdio.h>
int main (int argc, char ** argv){
enum{ max_string = 127};
static char string[max_string + 1] = "";
printf("Type in a linen");
fgets(string,max_string,stdin);
printf("the string is %sn",string);
return 0;
}
当我在Eclipse中运行程序时,我没有看到"键入一行"提示符。相反,如果我只输入一个响应,我将看到我在之后输入的内容:
Type in a line
the string is Hello World
为什么在我输入之前不先显示提示"键入一行" ?
需要刷新输出缓冲区。我只是加上了std::cout << std::endl;
,并包括了<iostream>
。我建议你开始使用std::cout
而不是printf
。它是类型安全的。我在Eclipse中对此进行了测试,没有刷新,这一行不会显示,刷新时它会显示。
如果你不想要移动到<iostream>
,我刚刚从<stdio.h>
测试了fflush(stdout)
,它也起作用。然而,我强烈鼓励你这么做,stdio.h是C的标准,iostream是c++的标准,既然你正在学习c++…
相关文章:
- 如何使用递归循环我的代码(当用户输入无效输入时,它会再次提示他们)?
- 如何确保用户在一行上提示输入一次时输入名字和姓氏?
- 为什么 std::cin 不提示用户输入?
- 如何使用打印到 PDF 打印机在 MFC 和 CView 中以编程方式打印而不提示输入文件名?
- 编写一个程序,提示用户输入一个整数,然后输出数字的单个数字和数字的总和
- C++:跳过第一个用户输入提示
- (显示金字塔)编写一个程序,该程序提示用户输入1到15的整数并显示金字塔
- 循环不提示用户输入(C )
- C++ 编写一个程序,提示用户以数字形式输入一个人的出生日期(投掷/接球)
- 使用提示用户输入笛卡尔平面中某些点的x-y坐标(浮点类型)的函数
- 如何提示用户在C++中输入正确的电子邮件地址格式
- 输入有效的输入值后仍有提示
- 当提示输入整数值时输入字符时,为什么程序会中断
- 提示输入CreateFile的凭据
- >使用 RegCreateKeyEx() 的 Windows 可执行文件不会提示输入 UAC 管理员权限并失败?
- 防止提示输入 PEM 密码
- 如何在不提示输入密码的情况下设置计划任务
- 如何使用循环显示菜单并重新提示输入
- c++ shell命令提示输入密码
- 如何同时(!CIN >> x)) 用于重新提示输入