help sos!c++primer 例题!

铁血萌少 2009-10-26 09:43:13
#include<iostream>
using namespace std;
int main()
{
int ival;
while (cin>>ival,!cin.eof())
while(!cin.eof())
{
if(cin.bad())
throw runtime_error("IO stream corrupted");
if(cin.fail())
{
cerr<<"bad date,try again"<<endl;
cin.clear(istream::failbit);
continue;
}
}
}


为何无法运行
...全文
87 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
铁血萌少 2009-10-26
  • 打赏
  • 举报
回复
谢楼上的了,查了
mstlq 2009-10-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 w514400413 的回复:]
楼上的大侠,我是照书抄的,拿错了啊!

[/Quote]

3楼不是告诉你错在哪一句了吗>_<?
铁血萌少 2009-10-26
  • 打赏
  • 举报
回复
楼上的,在google上输cin.clear(istream::failbit);可找到答案!
na2650945 2009-10-26
  • 打赏
  • 举报
回复
等待高手。
我也不明白啦。
关于输入输出流。
铁血萌少 2009-10-26
  • 打赏
  • 举报
回复
楼上的大侠,我是照书抄的,拿错了啊!
mstlq 2009-10-26
  • 打赏
  • 举报
回复
#include <fstream>
void clear( iostate flags = ios::goodbit );

The function clear() does two things:

it clears all io stream state flags associated with the current stream,
and sets the flags denoted by flags
mstlq 2009-10-26
  • 打赏
  • 举报
回复
请楼主好好理解查查手册,理解
cin.clear(istream::failbit);
的含义……
铁血萌少 2009-10-26
  • 打赏
  • 举报
回复
当输
1
2
3
a
时,“data bad ,try again”无限循环
铁血萌少 2009-10-26
  • 打赏
  • 举报
回复
发错了

#include<iostream>
using namespace std;
int main()
{
int ival;
while (cin>>ival,!cin.eof())
{
if(cin.bad())
throw runtime_error("IO stream corrupted");
if(cin.fail())
{
cerr<<"bad date,try again"<<endl;
cin.clear(istream::failbit);
continue;
}
}
}

64,641

社区成员

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

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