C++ Principle 6편


프로그램 작성


cin : cin에는 입력된 버터가 들어있어서 버터에서 필요할 때마다 하나씩 꺼낼 수 있다. 이 하나의 단위는 cin » __에 입력되는 값의 타입에 따라서 달라지는데, char 타입이면 1글자씩 string 타입이면 공백 단위로 입력받을 수 있다. double이라면 .과 숫자가 등장할 때 다음 .까지를 하나의 단위로 인식한다던가 하는 세세한 차이가 있지만 이 과정에서 __에 입력할 수 있는 값이 아니면 오류를 띄우면서 프로그램을 중지시킨다.

From the point currently in the stream, skip any whitespace which might be there and then keep reading as long as possible & necessary to get a valid representation of x.

Let us disregard for a moment the fact that input comes from the keyboard. The content of the stream at start is a b LINEFEED. You execute cin » c, which will read the first character, a, from input. That’s enough to fill in c, so reading stops. The cin stream now contains b LINEFEED. The variable c is then written to standard output.

Another cin » c comes next, so one more character is read (this time b). Again, one character is enough, so reading ends and the stream contents is just LINEFEED. The b is then sent to the standard output stream.

The fact that the standard input and standard output streams are normally tied to the console does not affect their internal working in any way. cin doesn’t “forget” what was in it just because some output appeared on the screen in the meantime. In particular, cin reads the keyboard, not “characters on the console.” It just so happens that pressing keys both echoes them on the console and feeds them to cin.

So the fact that your program has output the character a in the meantime has no effect on the contents of the cin stream.

####버퍼 버퍼란 데이터를 전송할 때 시간의 차이나 데이터 흐름의 속도 차이가 생겼을 때 일시적을 데이터를 보관하는 영역


© 2017. by yunsu

Powered by dolphin