How to find the shortest word in the string C++
<p>I need a help.
I have a function which print Longest Word in sentence.
But how to display shortest word?</p>

<p>string text = "My name is Bob";</p>

<pre><code>void LongestWord(string text)
{
string tmpWord = "";
string maxWord = "";

for(int i=0; i &lt; text.length(); i++)
{
    /// If founded space, rewrite word
    if(text[i] != ' ')
        tmpWord += text[i];
    else
        tmpWord = "";
    /// All the time check word length and if tmpWord &gt; maxWord =&gt; Rewrite.
    if(tmpWord.length() &gt; maxWord.length())
        maxWord=tmpWord;
}
cout &lt;&lt; "Longest Word: " &lt;&lt; maxWord &lt;&lt; endl;
cout &lt;&lt; "Word Length: " &lt;&lt; maxWord.length() &lt;&lt; endl;
}
</code></pre>