title: How do I iterate over the words of a string?
body: <p>How do I iterate over the words of a string composed of words separated by whitespace?</p>
  <p>Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer elegance over efficiency. My current solution:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main() {
      string s = &quot;Somewhere down the road&quot;;
      istringstream iss(s);
  
      do {
          string subs;
          iss &gt;&gt; subs;
          cout &lt;&lt; &quot;Substring: &quot; &lt;&lt; subs &lt;&lt; endl;
      } while (iss);
  }
  </code></pre>