title: C++ find in vector
body: <p>I am trying to do function that would return postition where occurrence was found in vector. But my return value is always 0 and I'm sure that there is a match.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>int findInItemvector(vector&lt;Item&gt; vec, string name)
  {
      for(vector&lt;Item&gt;::iterator it = vec.begin(); it &lt; vec.end(); it++)
      {
          if(it-&gt;getName() == name)
          {
              return it - vec.begin(); 
              break;
          }
          else
          {
              return 0;
          }
  
      }
  }
  </code></pre>