I can't tell if I'm just missing something obvious here but I cannot seem to get find_if to work.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isspace(char c)
{
return c == ' ';
}
int main()
{
string text = "This is the text";
string::iterator it = find_if(text.begin(), text.end(), isspace);
cout << *it << endl;
return 0;
}
I've looked at the example here, http://www.cplusplus.com/reference/algorithm/find_if/, which compiles and runs but I cannot see the difference between that and my program other than the vector -> string thing but I don't see why that would make a difference.
I know cctype has the better functions for isspace but I wanted to make sure that wasn't messing me up.
My error:
test.cpp: In function ‘int main()’:
test.cpp:16:68: error: no matching function for call to ‘find_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)’
string::iterator it = find_if(text.begin(), text.end(), isspace);
^
test.cpp:16:68: note: candidate is:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from test.cpp:3:
/usr/include/c++/4.8/bits/stl_algo.h:4456:5: note: template<class _IIter, class _Predicate> _IIter std::find_if(_IIter, _IIter, _Predicate)
find_if(_InputIterator __first, _InputIterator __last,
^
/usr/include/c++/4.8/bits/stl_algo.h:4456:5: note: template argument deduction/substitution failed:
test.cpp:16:68: note: couldn't deduce template parameter ‘_Predicate’
string::iterator it = find_if(text.begin(), text.end(), isspace);
^