cin>>ws;这条语句是什么意思啊?

kialo 2004-10-13 11:02:47
谢谢了。!~~~~赫赫
...全文
1960 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
duzidizou 2010-06-06
  • 打赏
  • 举报
回复 3
ws指的是std::ws,是用来去除空格的
比如:
int i;
float f;
char buf[100];
cin >> i >> f;
cin >> std::ws;
cin.getline(buf, 100);
这段程序在运行时,你需要输入一个整形数,然后输入一个空格,再输入一个浮点数。然后,你可以输入若干空格,最后输入字符串。
cin在读取到整数和浮点数之后,会继续读取你输入的字符串,并且忽略浮点数和字符串之间的若干空格。
zhoujiamurong 2005-03-09
  • 打赏
  • 举报
回复
学习一下
song x 2004-10-13
  • 打赏
  • 举报
回复
由键盘输入一个数或字符,将该值赋给变量 ws
浩方软件HFWMS 2004-10-13
  • 打赏
  • 举报
回复
输入语句啊
并把值负给变量ws
licki 2004-10-13
  • 打赏
  • 举报
回复
cin >> ws;
用户输入,并赋值给ws。
类似于ANSI C下的scanf()函数吧。
Angus83 2004-10-13
  • 打赏
  • 举报
回复
等待用户输入信息到ws变量中
shiyinan 2004-10-13
  • 打赏
  • 举报
回复
这里有虚幻引擎下载bbs.chaosstars.com
看起来还不错
demo001 2004-10-13
  • 打赏
  • 举报
回复
是定义流格式用的

忽略流中的空格
阿浪 2004-10-13
  • 打赏
  • 举报
回复
晕,他的那个程序能在什么平台下编译啊?感觉错误的地方太多了……
newthes 2004-10-13
  • 打赏
  • 举报
回复
用中文解释呀,老兄,大家都想了解耶
void_pointer 2004-10-13
  • 打赏
  • 举报
回复
MSDN上查到了:

Standard C++ Library Reference

wsSee Also
<istream> Members
Skips white space in the stream.

template class<Elem, Tr>
basic_istream<Elem, Tr>& ws(
basic_istream<Elem, Tr>& _Istr
);
Parameter
_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.

See Also
<istream> Members

void_pointer 2004-10-13
  • 打赏
  • 举报
回复
std::ws;

cin >> ws; // 应该是起一个去除输入行首尾空格的作用.

不知道对不对,期待STL高人讲解.:)
snow810211 2004-10-13
  • 打赏
  • 举报
回复
输入一个数据并且赋给变量ws
wxy_8191 2004-10-13
  • 打赏
  • 举报
回复
应该就是输入语句吧?
dlyy 2004-10-13
  • 打赏
  • 举报
回复
读作 c in(印) 呵呵~~输入流~输入一个赋给ws的值
keple 2004-10-13
  • 打赏
  • 举报
回复
没有定义??能通过编译吗?
zoohoo 2004-10-13
  • 打赏
  • 举报
回复
能编译过吗?上面的程序
Kartor 2004-10-13
  • 打赏
  • 举报
回复
关注!!!!!
kialo 2004-10-13
  • 打赏
  • 举报
回复
不对啊。我没有定义ws这个变量啊。原代码如下:

#include <strstrea.h>
#define SZ 100

void main()
{
cout<<"type an int,a float and a string:";
int i;
float f;
cin>>i>>f;
cin>>ws; //Throw away white space
char buf[SZ];
cin.getline(buf,SZ); //Get rest of the line
//(cin.rdbuf() would be awkward)
ostrstream os(buf,SZ,ios::app);
os<<endl;
os<<"integer="<<i<<endl;
os<<"float="<<f<<endl;
os<<ends;
cout<<buf;
cout<<os.rdbuf(); //Same effect
cout<<os.rdbuf(); //Not the same effect
}

65,183

社区成员

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

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