while(cin>>a>>b)跟while(scanf("%d %d"&a,&b))有什么区别
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嘛
#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嘛