I changed my code, as CornedBee told:
Code:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
using namespace std;
typedef std::istream_iterator<int> in;
cout << "Enter numbers, to stop enter Ctrl-Z:" << endl;
int sum=0, cnt=0;
cout << for_each(
in(cin),
in(),
(sum += _1,cnt++)
);
cout << "Sum: " << sum << " Average: " << (sum/cnt) << endl;
return 0;
}
but does not work:
Code:
Input:
1 2 3 4 5
Output:
Sum: 15 Average: 15