title: Function to get String Word by Word
body: <p>I am trying to write a function which gets a String, it will then look for the first word  and return it, and then delete it from the Inputstring. This all works but the problem I am facing is that once there are more than one whitespace it starts deleting letters from the next word in the string, which i dont want because i might need to check the second word for its properties too by calling the function again.</p>
  
  <pre><code>std::string extractWord (std::string&amp; inspectThis)
  {
    std::string firstWord;
    int i = 0;
  
    for (int count = 0; count &lt; inspectThis.length(); count++) {
      if (isalpha(inspectThis[count]))
        firstWord += inspectThis[count];
      else if (firstWord.length() &gt; 0)
        break;
    }
    int pos = inspectThis.find(firstWord);
    inspectThis.erase(pos, pos + firstWord.length());
  
    return firstWord;
  }
  
  
  
  int main() {
    std::string name = "   Help  Final  Test";
    std::cout&lt;&lt;extractWord(name) &lt;&lt; std::endl;
    std::cout&lt;&lt;extractWord(name) &lt;&lt; std::endl;
    std::cout&lt;&lt;extractWord(name) &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>When I test my function like this the output will be: "Help inal est"</p>