title: My code compile, execute but program crashes at the end
body: <pre><code>// program that split a string and stock words in a vector array
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main()
  {
  cout &lt;&lt; "substring using vector test\n" &lt;&lt; endl;
  
  bool reste(1);
  vector&lt;string&gt; mots;   // our vector 'word' mots is french vector
  size_t found(-1);      // init at - 1 because i need to wirte +1 to start at 0 
  int prevFound(-1);     // same explanation, prevFound meaning previous found
  string chaine ("let's test this piece of code");  
  
  do
  {
   found = chaine.find(" ",found+1);  // looking for the first space encountered
  
  
  if (found!=string::npos)   // if a space is found..
  {
     cout &lt;&lt; "\nSpace found at: " &lt;&lt; found &lt;&lt; '\n';  // position of the first space
     mots.push_back(chaine.substr(prevFound+1,found-prevFound)); // add a 'case' in vector and substract the word //
     prevFound = found;  // stock the actual pos in the previous for the next loop
  
  
  }
  if (found==string::npos)    // if no space is remaining, extract last word
  {
     cout &lt;&lt; "\nlast word\n\n" &lt;&lt; endl;
     mots.push_back(chaine.substr(prevFound+1,found-prevFound));
     reste = 0;
  }
  
  }while (reste);   
  
  
  cout &lt;&lt; "\nraw sentence : " &lt;&lt; chaine &lt;&lt; endl;
  
  unsigned int taille = mots.size();  // taille meaning size
  cout &lt;&lt; "number of words" &lt;&lt; taille &lt;&lt; "\n" &lt;&lt; endl;
  
  for (int i(0); i&lt;=taille; i++)  // loop showing the extracted words
  {
  cout &lt;&lt; mots[i] &lt;&lt; '\n';
  }
  return 0;
  }
  </code></pre>
  
  <p>Thanks for your time.
  I tried to translate most of my code coded in my mother tongue, i might be irrelevent on my expalanations.
  I've been learning c++ online for two weeks now, be clement.</p>
  
  <p>I just want to know why my code compile and execute but crashes at the end, my code do fine with static arry.
  Maybe i need a set container ?
  If yes, can someone correct my code with std::set.
  Thanks in advance.</p>