Problem with std::find
This is the error message I get when I execute the code below
Testing.cpp: In function ‘int main()’:
Testing.cpp:28:45: error: could not convert ‘std::find<__gnu_cxx::__normal_iterator<Sales_item*, std::vector<Sales_item> >, Sales_item>(items.std::vector<_Tp, _Alloc>::begin<Sales_item, std::allocator<Sales_item> >(), items.std::vector<_Tp, _Alloc>::end<Sales_item, std::allocator<Sales_item> >(), (*(const Sales_item*)(& item)))’ from ‘__gnu_cxx::__normal_iterator<Sales_item*, std::vector<Sales_item> >’ to ‘bool’
if (find(items.begin(), items.end(), item)) {
^
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int main()
{
vector<Sales_item> items;
Sales_item item;
while (cin >> item) {
items.push_back(item);
if (find(items.begin(), items.end(), item)) {
}
}
return 0;
}
|
Class: http://pastebin.com/RTae9YsK
No idea why.
std::find() returns an
iterator
1 2
|
// if (find(items.begin(), items.end(), item))
if ( find(items.begin(), items.end(), item) != items.end() ) // found it
|
Oh thanks m8
Topic archived. No new replies allowed.