title: Need to split string into vector with delimiter
body: <p>The following code is supposed to split a string with delimiters using a function.</p>
  
  <p>Given the following function declaration:</p>
  
  <pre><code>vector&lt;string&gt; split(string target, string delimiter);
  </code></pre>
  
  <p>I need to implement the function so that it returns a vector of substrings in <code>target</code> that are separated by the string <code>delimiter</code>. For example:</p>
  
  <pre><code>split("10,20,30", ",")
  </code></pre>
  
  <p>should return a <code>vector</code> with the strings "10", "20", and "30". Similarly, </p>
  
  <pre><code>split("do re mi fa so la ti do", " ")
  </code></pre>
  
  <p>should return a <code>vector</code> with the strings "do", "re", "mi", "fa", "so", "la", "ti", and "do".</p>
  
  <p>My code only outputs the first element of the <code>vector</code>. I don't see anything wrong with the function implementation.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  vector&lt;string&gt; split(string, string);
  
  int main()
  {
      vector&lt;string&gt; v;
      string target;
      string delim;
      split(target, delim);
      v = split(target, delim);
      for (unsigned long i = 0; i &lt; v.size(); i++)
          cout &lt;&lt; v[i] &lt;&lt; " ";
  }
  
  vector&lt;string&gt; split(string target, string delim)
  {
      cout &lt;&lt; "Enter string: "&lt;&lt; endl;
      getline(cin, target);
      cout &lt;&lt; "Enter delimiter:" &lt;&lt; endl;
      getline(cin, delim);
      vector&lt;string&gt; v;
      size_t x = target.find(delim);
      while (x!= string::npos) {
          v.push_back(target.substr(0,x));
          target = target.substr(x);
          x = target.find(delim);
      }
      return v;
  }
  </code></pre>