std::search Algorithm Error

Why am I getting an error on the search algorithm? If I put e in place of s.end() it works but I'm just wondering why it won't work as it is now.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
string splitDate(string s)
{
	typedef string::const_iterator iter;
	string ret;
	string searchVal = ": ";
	iter b = s.begin();
	iter e = s.end();

	while (b != s.end())
	{
		b = search(b, s.end(), searchVal.begin(), searchVal.end());
		// It works if I put e in place of s.end()
		b += searchVal.size();
		if (b != s.end())
			ret = string(b, s.end());
	}
	return ret;
}
Last edited on
Which error are you getting?
Error 1 error C2780: '_FwdIt1 std::search(_FwdIt1,_FwdIt1,_FwdIt2,_FwdIt2,_Pr)' : expects 5 arguments - 4 provided c:\users\dj\documents\visual studio 2010\projects\work hour manager\work hour manager\split.cpp 15

Error 2 error C2782: '_FwdIt1 std::search(_FwdIt1,_FwdIt1,_FwdIt2,_FwdIt2)' : template parameter '_FwdIt1' is ambiguous c:\users\dj\documents\visual studio 2010\projects\work hour manager\work hour manager\split.cpp 15

5 IntelliSense: no instance of "search" matches the argument list c:\users\dj\documents\visual studio 2010\projects\work hour manager\work hour manager\split.cpp 15
Bumped since I'm having the same problem on another project now and I find it really stupid how I need to define a new iterator in order to use the algorithm.
b is a const iterator, s.end() is not. Either use e (since it is const) or you will have to specify your template arguments.
string splitDate(const string &s) This way s.end() will return a const iterator.
Thank you ne555, that was the solution I was looking for.
Topic archived. No new replies allowed.