Effect of noskipws on cin>>

。_饼干妹妹 提交于 2019-11-28 11:28:45

The basic algorithm for >> of a string is:

skip whitespace
read and extract until next whitespace

If you use noskipws, then the first step is skipped. After the first read, you are positionned on a whitespace, so the next (and all following) reads will stop immediatly, extracting nothing.

>> to a string will never put whitespace into the string. More generally, using >> with noskipws is problematic, since whitespace is always a separator for >>; it may make sense to use it punctually, but it should generally be reset immediately after it has been used. (The once case where it might make sense is when using >> to a char. In this case, the stream always extracts one character.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!