There is no suitable function to call 'find'

I have the following code:

#include <algorithm> #include <vector> #include <iostream> #include <stdio.h> using namespace std; int main() { typedef vector<int> IntContainer; typedef IntContainer::iterator IntIterator; IntContainer vw; IntIterator i = find(vw.begin(), vw.end(), 5); if (i != vw.end()) { printf("Find 5 in vector\n"); // found it } else { printf("Couldn't find 5 in vector\n"); // couldn't found it } return 0; } 

I try to compile it on Ubuntu with gcc 4.7.1 and get the following error:

 vec_test.cpp: In function 'int main()': vec_test.cpp:27:46: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int)' vec_test.cpp:27:46: note: candidate is: In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/locale_facets.h:50:0, from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/basic_ios.h:39, from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/ios:45, from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/ostream:40, from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/iostream:40, from vec_test.cpp:3: /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/streambuf_iterator.h:371:5: note: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> > >::__type std::find(std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >, std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >, const _CharT2&) /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/streambuf_iterator.h:371:5: note: template argument deduction/substitution failed: vec_test.cpp:27:46: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >' 

This code does nothing, since the vector is not initialized with any content, but it must be compiled.

I suspect this is a gcc problem, but after many digging, I despaired. Please let me know if anyone has encountered this problem and knows how to solve it.

+4
source share
1 answer

Maybe some file defines the find function in the global namespace?

Have you tried to indicate full coverage? This means that std :: find instead of find. This may help remove this strange line :

 using namespace std; 

However, this is not what I expect. I would call it a mistake.

0
source

All Articles