Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For space separated strings, then you can do this:</p> <pre><code>std::string s = "What is the right way to split a string into a vector of strings"; std::stringstream ss(s); std::istream_iterator&lt;std::string&gt; begin(ss); std::istream_iterator&lt;std::string&gt; end; std::vector&lt;std::string&gt; vstrings(begin, end); std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator&lt;std::string&gt;(std::cout, "\n")); </code></pre> <p>Output:</p> <pre><code>What is the right way to split a string into a vector of strings </code></pre> <p>Online Demo : <a href="http://ideone.com/d8E2G" rel="noreferrer">http://ideone.com/d8E2G</a></p> <hr> <h1>string that have both comma and space</h1> <pre><code>struct tokens: std::ctype&lt;char&gt; { tokens(): std::ctype&lt;char&gt;(get_table()) {} static std::ctype_base::mask const* get_table() { typedef std::ctype&lt;char&gt; cctype; static const cctype::mask *const_rc= cctype::classic_table(); static cctype::mask rc[cctype::table_size]; std::memcpy(rc, const_rc, cctype::table_size * sizeof(cctype::mask)); rc[','] = std::ctype_base::space; rc[' '] = std::ctype_base::space; return &amp;rc[0]; } }; std::string s = "right way, wrong way, correct way"; std::stringstream ss(s); ss.imbue(std::locale(std::locale(), new tokens())); std::istream_iterator&lt;std::string&gt; begin(ss); std::istream_iterator&lt;std::string&gt; end; std::vector&lt;std::string&gt; vstrings(begin, end); std::copy(vstrings.begin(), vstrings.end(), std::ostream_iterator&lt;std::string&gt;(std::cout, "\n")); </code></pre> <p>Output:</p> <pre><code>right way wrong way correct way </code></pre> <p>Online Demo : <a href="http://ideone.com/aKL0m" rel="noreferrer">http://ideone.com/aKL0m</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload