How do I use accumulate from STL

Hi,
could anyone tell me how to use accumulate from STL. I get following error when I compile.



Bonuses.cc: In member function ‘std::vector<int, std::allocator<int> > Bonuses::getDivision(std::vector<int, std::allocator<int> >)’:
Bonuses.cc:16: error: ‘accumulate’ was not declared in this scope



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <vector>
#include <algorithm>

using namespace std;

class Bonuses
{
	public:
		vector <int> getDivision(vector <int>);
};

vector <int> Bonuses::getDivision(vector <int> bonus)
{
	vector<int> my_bonuses;
	vector<int>::iterator itr;
	int total_points = accumulate(bonus.begin(), bonus.size(), 0);
	
	total_points;
	
	return my_bonuses;
}



Thanks...!!!
You need to include <numeric>, not <algorithm>.
Is there any other error in this code? Because i'm getting another error after modification...

Thanks..

Bonuses.cc: In member function ‘std::vector<int, std::allocator<int> > Bonuses::getDivision(std::vector<int, std::allocator<int> >)’:
Bonuses.cc:16: error: no matching function for call to ‘accumulate(std::vector<int, std::allocator<int> >&, size_t, int)’
line 16
accumulate (start,end,initial value,operation)
default operation is sum
 
accumulate(bonus.begin(),bonus.end(),0);
Thanks......!!!
Topic archived. No new replies allowed.