The input symbol stream at the end of the win

In the "C ++ Primer" I saw that the input stream terminator at the win is Ctrl + Z, then wrote a piece of code to test and found to be entered twice CTRL + Z will not quit:

#include<iostream>
using namespace std;

main int () {
        char A;
        the while (CIN >> A) A COUT << << endl;
        return 0;
} at the Baidu, found reasons:

 (The following excerpt from luosiyong the space Baidu: http://hi.baidu.com/luosiyong/blog/item/b66a97184c55c00035fa41b0.html )
input buffer is a line buffer. After entering the string of characters from the keyboard and press Enter, these characters are first stored in the buffer to the input. Every time the Enter key is pressed, cin.get () will detect whether the input data buffer has been read. cin.get () will also check is made as to whether there is flow mark the end of the keyboard Ctrl Z or Ctrl + D + key is pressed, it checks in two ways: blocking and non-blocking.   
     
Blocking check mode refers to the Enter key is pressed only after fishes have had if Ctrl + Z key combination is pressed check pattern refers to a non-blocking mode immediately after the press Ctrl + D response. If before pressing Ctrl + D characters has been input from the keyboard, the Ctrl + Enter action is equivalent to D, i.e., the input buffer for these characters to read, in which case Ctrl + D no longer play stream terminator role. If there is no keyboard input before pressing Ctrl + D, then Ctrl + D is the end of the current signal.   
     
Windows systems generally use blocking the inspection Ctrl + Z, Unix / Linux systems generally use non-blocking check Ctrl + D.
     
This way there is a blocking characteristics: only after pressing Enter will it be possible to detect whether or not there before pressing Ctrl + Z. Another feature: if the input buffer has not detected the data readable Ctrl + Z (as the data to be read, can not be considered to end of the stream). Another point that needs to know: Ctrl + not an ordinary ASCII value Z produced, that is not a character that it produces, so it will not with other characters entered from the keyboard as can be stored in the input buffer.
     
Abcd ^ input from the keyboard after a carriage return z on Windows systems is addressed: the action of the carriage, in front of the other characters abcd is supplied to the input buffer (Note: the above mentioned, no ^ z characters, will not stored in the input buffer, no buffer is present ^ z). In this case, cin.get () detected by the input buffer has data exists (and therefore will not check input ^ z), then reads the corresponding data from the buffer. If you are reading is over, then re-enter the buffer becomes empty, cin.get () waits for new input. It is seen, despite press ^ z, but since there are other character input (ABCD), so that the flow does not end before.   
     
Therefore, the end of the input stream condition is: ^ z Before there can be no character input (except carriage return), or ^ z ending stream would not achieve the role.

There is a problem   
if you enter abcd ^ zabcd   
program Echo abcd   
and waits for input, which is no longer ^ Z after the show  

-----------------------------------------------   
If the input buffer readable data area has not detected the Ctrl + Z (as the data to be read, can not be considered to end of the stream). Another point that needs to know: Ctrl + not an ordinary ASCII value Z produced, that is not a character that it produces, so it will not with other characters entered from the keyboard as can be stored in the input buffer.  

>> If you enter ^ zabcd ABCD   
>> Echo program ABCD   
>> and waits for input, that is, after the ^ Z no longer shows   
>> Why did not deal with it later?   
^ Z can be understood to terminate the keyboard input in this case, but not the flow is terminated

================================================================================

Remarks:

When the console running, the key combination Ctrl + C can exit the program at any time, pause / break key (in the function key area) may suspend execution of the program.

 

 

Reproduced in: https: //www.cnblogs.com/kungfupanda/archive/2012/06/20/2556619.html

Guess you like

Origin blog.csdn.net/weixin_34167819/article/details/94494233