There are few problems in which we can't determine length of input. Program is meant to process all the input it is given and terminates after no input is left in stdin.
For Example
Problem : Print Sum in new line for every two integer in a line.
Sample Input —
5 6
10 15
3 4
Sample Output -
11
25
7
Similar Question on SPOJ
http://www.spoj.com/problems/NHAY/
What is a good way to handle this kind of Inputs??
For two integer inputs, u can use while(cin>>a>>b) cout<<a+b; Or while(scanf("%d%d",&a,&b) == 2) cout<<a+b; Or while(scanf("%d%d",&a,&b) != EOF) cout<<a+b;
Thanks!
or you can check
rdstate()
andeofbit
, take a look: http://www.cplusplus.com/reference/ios/ios/rdstate/