Guest User

Untitled

a guest
Oct 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iterator>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class myiterator : public iterator<input_iterator_tag, string>
  7. {
  8.     string p;
  9.     unsigned int i;
  10. public:
  11.     myiterator(string x)
  12.     {
  13.         p = x;
  14.         i = 0;
  15.     }
  16.  
  17.     bool hasNext()
  18.     {
  19.         return i<p.length();
  20.     }
  21.  
  22.     char next()
  23.     {
  24.         int k = i;
  25.         i++;
  26.         return p[k];
  27.     }
  28.  
  29.     void add(string x)
  30.     {
  31.         p += x;
  32.     }
  33.  
  34.     void startPosition()
  35.     {
  36.         i = 0;
  37.     }
  38.  
  39.     void remove()
  40.     {
  41.     }
  42.  
  43. };
  44.  
  45.  
  46.  
  47.  
  48.  
  49. int main () {
  50.     string numbers = "500154821254";
  51.     myiterator it(numbers);
  52.     it.next();
  53.     it.startPosition();
  54.     it.add("aaaa");
  55.     while(it.hasNext())
  56.         cout << it.next();
  57.     cout << "\n";
  58.  
  59.  
  60.  
  61.     return 0;
  62. }
Add Comment
Please, Sign In to add comment