返回信息流#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <deque>
using namespace std;
int main()
{
list<int> list_num;
int iter;
cout<<"please enter the number: ";
while (cin>>iter)
{
list_num.push_back(iter);
}
deque<int> even_dq,odd_dq;
for (list<int>::iterator ite;ite=list_num.begin(),
ite!=list_num.end();++ite)
{
if (*ite%2==0)
{
even_dq.push_back(*ite);
}
else
{
odd_dq.push_back(*ite);
}
}
deque<int>::iterator it;
it=even_dq.begin();
while (it!=even_dq.end())
{
cout<<*it<<" ";
++it;
}
cout<<endl;
it=odd_dq.begin();
while (it!=odd_dq.end())
{
cout<<*it<<" ";
++it;
}
cout<<endl;
return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #47184同步于 2010/12/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
大侠帮助调试一下 while(cin>>iter)怎么退出
zmqing
2010/12/1镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
EOF...
windows下,Ctrl+Z;
unix下,Ctrl+D;
改天把这个加到常见问题里面...
【 在 zmqing (qing) 的大作中提到: 】
: #include <iostream>
: #include <string>
: #include <vector>
: ...................
【 在 shenlei 的大作中提到: 】
: EOF...
: windows下,Ctrl+Z;
: unix下,Ctrl+D;
: ...................
用了Ctrl+Z 还是不行呢~~用VC6.0和Dev-C++都不行啊
ctrl+z
回车几次……
【 在 zmqing (qing) 的大作中提到: 】
: 用了Ctrl+Z 还是不行呢~~用VC6.0和Dev-C++都不行啊
【 在 zmqing 的大作中提到: 】
: : EOF...
: : windows下,Ctrl+Z;
: : unix下,Ctrl+D;
: ...................
回车之后Ctrl + z……
这里应该有缓冲区的问题……
能不能具体说一下,还是调不出来
【 在 shenlei 的大作中提到: 】
: : : EOF...
: : : windows下,Ctrl+Z;
: : : unix下,Ctrl+D;
: ...................
cin当读取错误时会返回false, 读取eof时也会返回false
至于 lz的程序,F6(ctrl+z)可以退出循环。 事实上,你的iter是int型,你随便搞个不是int型的给他输入,他一失败就退了