title: Split string at space and return first element in C++
body: <p>How do I split string at space and return first element? For example, in Python you would do:</p>
  
  <pre><code>string = 'hello how are you today'
  ret = string.split(' ')[0]
  print(ret)
  'hello'
  </code></pre>
  
  <p>Doing this in C++, I would imagine that I would need to split the string first. Looking at this online, I have seen several long methods, but what would be the best one that works like the code above? An example for a C++ split that I found is</p>
  
  <pre><code>#include &lt;boost/regex.hpp&gt;
  #include &lt;boost/algorithm/string/regex.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  using namespace boost;
  
  void print( vector &lt;string&gt; &amp; v )
  {
    for (size_t n = 0; n &lt; v.size(); n++)
      cout &lt;&lt; "\"" &lt;&lt; v[ n ] &lt;&lt; "\"\n";
    cout &lt;&lt; endl;
  }
  
  int main()
  {
    string s = "one-&gt;two-&gt;thirty-four";
    vector &lt;string&gt; fields;
  
    split_regex( fields, s, regex( "-&gt;" ) );
    print( fields );
  
    return 0;
  }
  </code></pre>