title: Why can't I access directly in vector iterator?
body: <p>Why can't i do like this? In the below code, I can access from for loop, but not from outside loop?</p>
  
  <pre><code>class root
  {
      string name;
  
  public:
  
      root()
      {
      }
  
      root(const string&amp; okay)
      {
          name = okay;
      }
  
      void setRoot(const string&amp; okay)
      {
          name = okay;
      }
  
      string getRoot()
      {
          return name;
      }
  
      ~root ()
      {
      }
  }; // class root
  
  int main()
  {
      string a;
      vector&lt;root&gt; Root;
      vector&lt;root&gt;::iterator oley;
      root okay;
  
      for (int i=0; i&lt;5;i++)   //this is to add strings in vector
      {
          cin &gt;&gt; a;
          okay.setRoot(a);
          Root.push_back(okay);
      }
  
      for (oley=Root.begin(); oley!=Root.end(); oley++)   //this is to print vectors in scren
      {
          cout &lt;&lt; (*oley).getRoot() &lt;&lt; endl;
      }
      oley = Root.begin();
      cout &lt;&lt; (*oley + 2).getRoot();   //this is error. What is required to make it legal?
  
      return 0;
  }
  </code></pre>
  
  <p>So, if we can access iterator from for loop, why can't we do so in non-looped codes?</p>
  
  <pre><code>cout &lt;&lt; (*oley + 2).getRoot();   
  </code></pre>