求cin >>ws; 作用

walfud 2010-12-21 08:54:22
为避免"高人"直接贴msdn, 我先给你贴出来, 如果你真是高手, 请解释...

Skips white space in the stream. // 如何使用呢?


template class<Elem, Tr>
basic_istream<Elem, Tr>& ws(
basic_istream<Elem, Tr>& _Istr
);


Parameters
_Istr
A stream.

Return Value
The stream.

Remarks
The manipulator extracts and discards any elements ch for which use_facet< ctype<Elem> >(getloc). is(ctype<Elem>::space, ch) is true.

The function calls setstate(eofbit) if it encounters end of file while extracting elements. It returns _Istr.

Example
See operator>> for an example of using ws.

Requirements
Header: <istream>

Namespace: std

See Also
Concepts
<istream> Members
...全文
249 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
taodm 2010-12-24
  • 打赏
  • 举报
回复
找本《标准C++输入输出流与本地化》这个宝典吧。
walfud 2010-12-24
  • 打赏
  • 举报
回复
但是我输入"43214321fdsafdsa" 就会假死, 这是为什么呢?
Metrosexual 2010-12-22
  • 打赏
  • 举报
回复
++
[Quote=引用 1 楼 sghdls 的回复:]
用通俗的话讲, 就是: 从键盘读入一个ws对象 到 istream对象(cin)
[/Quote]
PG 2010-12-22
  • 打赏
  • 举报
回复
读取时忽略空格,
龙哥依旧 2010-12-22
  • 打赏
  • 举报
回复
也不知道c语言的stdio.h是怎么实现scanf函数的,cin是个c++中iostream里的一个对象,>>是一个重载的操作符,《C++ Primer Plus》讲流那张都没介绍那么深!
kisshujinwen 2010-12-21
  • 打赏
  • 举报
回复
Skips white space in the stream. // 如何使用呢?
你如果输入的字符串有空格,就只取空格前面的。。。
如果想读空格,就自己定义输入流对象,然后readline(),嘿嘿
谁学逆向工程 2010-12-21
  • 打赏
  • 举报
回复
从键盘输入(各种字符),输入到 ws 里
sghdls 2010-12-21
  • 打赏
  • 举报
回复

用通俗的话讲, 就是: 从键盘读入一个ws对象 到 istream对象(cin)

64,682

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧