Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- find.cc: In function ‘int main(int, char**)’:
- find.cc:34:16: error: no match for ‘operator+’ (operand types are ‘LI {aka std::_List_const_iterator<Ent>}’ and ‘int’)
- i = find(i + 1, l.end(), e1);
- #include <iostream>
- #include <algorithm>
- #include <list>
- #include <string>
- using namespace std;
- struct Ent {
- string name;
- Ent(const string& name) : name(name) { }
- bool operator== (const Ent& right) const {
- return name == right.name;
- }
- };
- int main(int argc, char *argv[])
- {
- list<Ent> l;
- for (char c = 'a'; c <= 'z'; c++) {
- Ent e(string(1, c));
- l.push_back(e);
- }
- Ent e1("p");
- typedef list<Ent>::const_iterator LI;
- LI i = find(l.begin(), l.end(), e1);
- int n = 0;
- while (i != l.end()) {
- ++n;
- i = find(i + 1, l.end(), e1);
- }
- cout << "find(" << e1.name << ") = " << n << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement