find_first_of problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <list>
#include <string>
#include <algorithm>

int main()
{
	std::list<std::string> ls;
	ls.push_back("one");
	ls.push_back("two");
	ls.push_back("three");
	ls.push_back("four");
	ls.push_back("five");

	std::string match = "two";
	auto it = std::find_first_of(ls.begin(), ls.end(), match.begin(), match.end());
	if(ls.end() != it)
	{
		std::cout << match << " found!" << std::endl;
	}

	std::cin.ignore();
	return 0;
}


error:

error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>'...


I don't see why? How to resolve this?
It would help if you posted the full error.

From http://www.sgi.com/tech/stl/find_first_of.html

* InputIterator is a model of Input Iterator.
* ForwardIterator is a model of Forward Iterator.
* InputIterator's value type is EqualityComparable, and can be compared for equality with ForwardIterator's value type.

In your case a string cannot be compared with a char.
Ok. Thanks.
Looks like std::find is what i want.
Topic archived. No new replies allowed.