Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
直接贴上代码:
#include<iostream>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<a+b<<endl;
}
return 0;
}
初学者可能存在如下疑问:
cin>>a>>b的返回值是多少?否则while语句怎么将其作为判断条件呢?
key:c++中,cin是对象,没有所谓的返回值,而cin可以作为判断条件的机理是if语句可以直接判断流,而while可以间接判断流,当成功输入时,条件为真。
PS:我是在xp下的vc6写的,结束使用ctrl+x操作的,而并不是ctrl+z。