C / C ++:我可以保持在光标后pressing当前行中输入? [英] C/C++ : Can I keep the cursor in the current line after pressing ENTER?
问题描述
我想问一下,如果有什么办法,使光标在当前行之后pressing ENTER !!
I would like to ask if there's any way to keep the cursor in the current line after pressing ENTER !!
例如...
#include<stdio.h>
int main()
{
int d=0;
printf("Enter a number : ");
scanf("%d",&d);
if(d%2)printf(" is a Odd number\n");
else printf(" is a Even number\n");
return 0;
}
输出的一个例子:
An example of output :
Enter a number : 10
is a Even number
...但我需要的是这样的事情:
... but what I need is something like that :
Enter a number : 10 is a Even number
我想提出是一个偶数(或是奇数)旁边用户输入的号码
I want to put "is a Even number" (or " is a Odd number") next to the number entered by user
推荐答案
简单的答案是不能。没有标准的C ++函数来控制这种行为,还是没有击中在最后输入读取数据(事实上,数据还没有真正被进入,直到你按下回车键,这样该程序将无法看到数据) 。
The simple answer is "you can't". There is no standard C++ functions to control this behaviour, or to read data without hitting enter at the end (in fact, the data hasn't really been "entered" until you hit enter, so the program won't see the data).
您可以使用非标准的功能,如额外的库,例如诅咒库或系统相关的code,但随后我们将不得不产生code。在一次读取的人物之一并使用code,你写融合在一起了。
You can use non-standard functionality, such as additional libraries, such as a "curses" library or system dependent code, but we would then have to produce the code to read characters one at a time and merge it together using code that you write.
我会建议您使用重复输出输入,并简单地做这样的事情:
I would suggest that you use the "repeat the input in the output", and simply do something like this:
printf("%d is", d);
if (d%2)
printf("an odd number\n");
else
printf("an even number\n");
这篇关于C / C ++:我可以保持在光标后pressing当前行中输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!