Hi, I have a list L
which needs to count how many 1s it has in it.
list<int> L;
L.push_back(14); L.push_back(5); L.push_back(22);
L.push_back(1); L.push_back(1); L.push_back(-7);
the function that i have been given is :
assert ( count(...,...,...) == 2);
i need to know what would replace the ...
's.
i have tried L.begin(), L.end(), 1
to replace the ...
's but it keeps giving me an error saying that is not allowed. So i need to replace the ...
's without adding any extra code.
this is the error that i have been getting:
error C2782: 'iterator_traits<_Iter>::difference_type std::count(_InIt,_InIt,const _Ty &)' : template parameter '_InIt' is ambiguous
Here is the exact code & error.
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <cassert>
using namespace std;
int main()
{
int A1[6] = {15,8,10,9,12,13};
vector<int> V(A1, A1+6);
list<int> L;
L.push_back(14); L.push_back(5); L.push_back(22);
L.push_back(1); L.push_back(1); L.push_back(-7);
count(L.begin(), L.end(), 1);
}
error C2782: 'iterator_traits<_Iter>::difference_type std::count(_InIt,_InIt,const _Ty &)' : template parameter '_InIt' is ambiguous
c:\program files\microsoft visual studio 9.0\vc\include\algorithm(160) : see declaration of 'std::count' 1>
could be 'unsigned int'