나는 간단한 프로그래밍을 가지고 std::find_if
을 호출한다. 나는 처음 두 개의 인수를 반복자로 전달하고 세 번째는 예측으로 전달한다고 생각하지만, 코드는 여전히 컴파일되지 않는다.내 프로그램에서 find_if가 작동하지 않는 이유는 무엇입니까?
#include <string>
#include <cctype>
#include <algorithm>
bool notspace(char ch);
bool space(char ch);
int main() {
typedef std::string::const_iterator iter;
iter i;
std::string s = "ab c";
i = std::find_if(i, s.end(),space);
return 0;
}
bool space(char ch) {
return std::isspace(ch);
}
오류 메시지 :
q-isspace.cpp: In function ‘int main()’:
q-isspace.cpp:12:38: error: no matching function for call to ‘find_if(iter&, std::__cxx11::basic_string<char>::iterator, bool (&)(char))’
i = std::find_if(i, s.end(),space);
^
In file included from /usr/include/c++/5/algorithm:62:0,
from q-isspace.cpp:3:
/usr/include/c++/5/bits/stl_algo.h:3806:5: note: candidate: template<class _IIter, class _Predicate> _IIter std::find_if(_IIter, _IIter, _Predicate)
find_if(_InputIterator __first, _InputIterator __last,
^
/usr/include/c++/5/bits/stl_algo.h:3806:5: note: template argument deduction/substitution failed:
q-isspace.cpp:12:38: note: deduced conflicting types for parameter ‘_IIter’ (‘__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >’ and ‘__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >’)
i = std::find_if(i, s.end(),space);
'i'와 'j'는 초기화되지 않습니다. 그렇다면'find_if'는 어디에서 시작해야할까요? – UnholySheep