首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

while(cin>>a>>b)跟while(scanf("%d %d"&a,&b))有什么区别

2012-06-24 
while(cinab)和while(scanf(%d %d,&a,&b))有什么区别?#include iostreamusing namespace stdint

while(cin>>a>>b)和while(scanf("%d %d",&a,&b))有什么区别?
#include <iostream>
using namespace std;

int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<a+b<<endl;
}
return 0;
}


#include <stdio.h>

int main()
{
int a,b;
while((scanf("%d %d",&a,&b)))
printf("%d\n",a+b);
return 0;
}

上面的代码AC了,下面的就一直是超时,这是为什么?

[解决办法]
cin对象的>>运算符返回的是NULL 当然可以不满足while的条件跳出

#difine EOF -1 你认为能跳出while嘛

热点排行