开发者

cin.get() in while loop not getting clear idea

in loop there is a cout statement which prints the character which provide from keyboard but inside loop it is not showing it even keep on typing keys from keyboar开发者_Python百科d but when we press enter it shows all of them all together why there is cin.get() outside loop and how does the cin.get() inside the loop behave actually

kindly reply thankx


The issue is that the operating system does not send the key strokes to your program until you hit return at the end of the line. Until then, you can edit the line with backspace or delete, and possibly other characters.

If you want to read one character at a time as typed, then you have to adjust the I/O mode of your terminal (on Unix and its derivatives) to 'raw' mode. This can be done with the curses library, though that's overkill (but convenient) if you are not going to use its display facilities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜