title: size_t i < _str.length creates endless loop in c++
body: <p>I have a class (Array), see ctor below. I want to create the method Array::read(_str) to give an object of Array the array typed in the interface. (for example string _str = "1 2 3")</p>
  
  <p>To determine the number of doubles the string should be converted into, I am counting the amount of spaces. The spaces are found correctly, but the loop does not end after the last space. (see output screen text).</p>
  
  <blockquote>
    <p>Why does the loop not end after finding both spaces ??</p>
  </blockquote>
  
  <p>ctor Array</p>
  
  <pre><code>Array::Array(int _size)
  {
      //ctor
      length = _size ;
      myArray = new double[length] ; // initialize array
  
      //default initialization
      for(size_t i = 0; i &lt; length; i++)
      {
          myArray[i] = i ;
      }
  }
  </code></pre>
  
  <p>method Array::read(string _str)</p>
  
  <pre><code>void Array::read(string _str)
  {
      // string_t find (&lt;what to search&gt;, &lt;starting pos&gt;) const ;
  
      // determine length (number of numbers)
      length = 0 ;
      int steps = 0 ;
      size_t i = 0 ;
  
      cout&lt;&lt;"Value of _str.length() : "&lt;&lt;_str.length() &lt;&lt;endl ; // test
  
      while( i &lt; _str.length() &amp;&amp; steps &lt; 100)
      {
  
          // search for space starting it i
          i = _str.find(" ",i ) ;
          if(i!=string::npos) // npos is greatest possible size_t
              cout&lt;&lt;"_ found at: 1 =  "&lt;&lt; i &lt;&lt;endl ;
  
          length ++ ;     // new number present
          i ++ ;          // next time start after space
          steps ++ ;      // to prevent endless loop
      }
      cout&lt;&lt;endl&lt;&lt;steps ;
  
      delete[] myArray ; // free old array
      myArray = new double[length] ; // allocate space
  
      // fill with doubles
  
  
  }
  </code></pre>
  
  <p>output screen text</p>
  
  <pre><code>Value of _str.length() : 5
  _ found at: i = 1
  _ found at: i = 3
  _found at: i = 1
  _found at: i = 3
  </code></pre>
  
  <p>This is repeating until <code>100</code> , thus the loop is only ended by the steps condition.</p>