Reputation: 23
Is there any alternative from using the .eof, by using cin as a condition for this?
while(cin.eof( )==false)
{
cin >> number;
sum += number;
count++;
}
Upvotes: 0
Views: 772
Reputation: 29965
Here's a better alternative:
while(cin >> number)
{
sum += number;
++count;
}
See Why is iostream::eof inside a loop condition (i.e. while (!stream.eof())
) considered wrong?
Upvotes: 1