Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. find.cc: In function ‘int main(int, char**)’:
  2. find.cc:34:16: error: no match for ‘operator+’ (operand types are ‘LI {aka std::_List_const_iterator<Ent>}’ and ‘int’)
  3. i = find(i + 1, l.end(), e1);
  4.  
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <list>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. struct Ent {
  13. string name;
  14. Ent(const string& name) : name(name) { }
  15. bool operator== (const Ent& right) const {
  16. return name == right.name;
  17. }
  18. };
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. list<Ent> l;
  23.  
  24. for (char c = 'a'; c <= 'z'; c++) {
  25. Ent e(string(1, c));
  26. l.push_back(e);
  27. }
  28.  
  29. Ent e1("p");
  30.  
  31. typedef list<Ent>::const_iterator LI;
  32.  
  33. LI i = find(l.begin(), l.end(), e1);
  34.  
  35. int n = 0;
  36. while (i != l.end()) {
  37. ++n;
  38. i = find(i + 1, l.end(), e1);
  39. }
  40.  
  41. cout << "find(" << e1.name << ") = " << n << endl;
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement