title: C++ find return the last word in the string variable text. string getFirstWord(text)
body: <p>I was trying to go to the end of the string, go back until the last space, then go forward until the end of the word and store that word in an empty string. No arrays or pointers are allowed.</p>
  
  <pre><code>string getLastWord(string text)
  {
      string lastword="";
      int last=text.size()- 1;
      int beginlast=0;
      if text == "";
      return  "";
      for (int i=last; i&gt;=1; i--)
      {
          if (isspace(text[i]))
              beginlast=beginlast+i;
      }
      for (int k=0; k!=text.size; k++)
      {
          if (isalpha(text[k]))
              lastword=lastword+lastword[k];
      }
      return lastword;
  }
  </code></pre>