Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The STL does not have such a method available already.</p> <p>However, you can either use C's <a href="http://en.cppreference.com/w/c/string/byte/strtok" rel="noreferrer"><code>strtok()</code></a> function by using the <a href="http://en.cppreference.com/w/cpp/string/basic_string/c_str" rel="noreferrer"><code>std::string::c_str()</code></a> member, or you can write your own. Here is a code sample I found after a quick Google search (<strong>"STL string split"</strong>):</p> <pre><code>void Tokenize(const string&amp; str, vector&lt;string&gt;&amp; tokens, const string&amp; delimiters = " ") { // Skip delimiters at beginning. string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". string::size_type pos = str.find_first_of(delimiters, lastPos); while (string::npos != pos || string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } } </code></pre> <p>Taken from: <a href="http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html" rel="noreferrer">http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html</a></p> <p>If you have questions about the code sample, leave a comment and I will explain.</p> <p>And just because it does not implement a <code>typedef</code> called iterator or overload the <code>&lt;&lt;</code> operator does not mean it is bad code. I use C functions quite frequently. For example, <a href="http://en.cppreference.com/w/c/io/fprintf" rel="noreferrer"><code>printf</code></a> and <a href="http://en.cppreference.com/w/c/io/fscanf" rel="noreferrer"><code>scanf</code></a> both are faster than <a href="http://en.cppreference.com/w/cpp/io/cin" rel="noreferrer"><code>std::cin</code></a> and <a href="http://en.cppreference.com/w/cpp/io/cout" rel="noreferrer"><code>std::cout</code></a> (significantly), the <a href="http://en.cppreference.com/w/c/io/fopen" rel="noreferrer"><code>fopen</code></a> syntax is a lot more friendly for binary types, and they also tend to produce smaller EXEs.</p> <p>Don't get sold on this <strong>"Elegance over performance"</strong> deal.</p>
    singulars
    1. This table or related slice is empty.
    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. 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