Why doesn't std::noskipws work, or what is it supposed to do?

后端 未结 2 1029
醉话见心
醉话见心 2020-12-20 15:17

First off my understanding is that

cin >> std::noskipws >> str;

should stick a whole line from cin like \"i have s

相关标签:
2条回答
  • 2020-12-20 15:48

    std::noskipws tells the istream to not skip any leading white space when attempting to read a type. When there is no leading white space, then the flag has no impact.

    0 讨论(0)
  • 2020-12-20 16:03

    std::skipws works as follows: std::istream always keeps a current read position. If std::skipws is set, before operator>> is called the current read position is advanced to the first non-space character.

    The behavior you're seeing (stop at the first space after 'i') is caused by operator>> for std::string (and std::wstring). That operator doesn't take the std::istream flags into account. An operator<< for another type may decide otherwise and continue even across spaces.

    0 讨论(0)
提交回复
热议问题