什么是标准输入缓冲区? [英] What is the standard input buffer?
问题描述
#include <stdio.h>
int main(void)
{
int c;
c = getchar();
putchar(c);
c = getchar();
putchar(c);
c = getchar();
putchar(c);
return 0;
}
我想知道这是为什么叫做三次函数与只输入一次线工作。
有些人解释说,我们在这种情况下,标准输入缓冲区的工作,那是一块内存。
我想读什么。你能告诉我一些资源?
I want to understand why the function that is called three times working with a line that was entered only once. Some guy explained, that we working with the standard input buffer in this situation, and that is a piece of memory. I want to read something about it. Can you advise me some resources?
推荐答案
这是你的终端(命令行窗口)的一项功能。
This is a feature of your terminal (the command line window).
在默认情况下,终端将从直到他presses输入/返回收集用户输入。然后,整条生产线已被推入程序的输入文件流(标准输入
,那就是,因为你使用&LT; stdio.h中&GT;
,而不是&LT; iostream的方式&gt;
,没有 CIN
参与)
By default, the terminal will collect input from the user until he presses Enter/Return. Then the whole line is pushed to the input filestream of your program (stdin
, that is; since you use <stdio.h>
rather than <iostream>
, there's no cin
involved).
由于您的程序没有处理间preting这是非常有用的所有键盘事件(例如,删除信件时,退格键是pressed)。它要处理的键盘本身的程序可以禁用此默认的输入模式。我认为,谷歌相关的关键字是的terminfo
或的termcap
。
This is useful because your program does not have to deal with interpreting all keyboard events (e.g. remove letters when Backspace is pressed). Programs which want to handle the keyboard themselves can disable this default input mode. I think the relevant Google keywords for that are terminfo
or termcap
.
具体涉及您的问题,一行输入好三个的getchar()
电话如果它包含三个字符。如果你只输入一个字符,程序应该等待后续的getchar()
呼吁更多的投入。
Specifically concerning your question, one line of input is good for three getchar()
calls if it contains three characters. If you entered only one character, your program should wait on the subsequent getchar()
calls for more input.
这篇关于什么是标准输入缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!