Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Some things to do in the code that should fix this, there might be a better and more elegant solution for this.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; using namespace std; int main() { string strLine("/cd/desktop/../test/"); string strTempString; vector&lt;int&gt; splitIndices; vector&lt;string&gt; splitLine; int nCharIndex = 0; int nLineSize = strLine.size(); // find indices if(nLineSize!=0 &amp;&amp; strLine[0]=='/') { splitLine.push_back(strLine.substr(0,1)); nCharIndex++; } for(int i = 1; i &lt; nLineSize; i++) { if(strLine[i] == '/') splitIndices.push_back(i); } // fill split lines for(int i = 0; i &lt;int(splitIndices.size()); i++) { strTempString = strLine.substr(nCharIndex, (splitIndices[i] - nCharIndex)); splitLine.push_back(strTempString); nCharIndex = splitIndices[i] + 1; } } </code></pre> <p>Edit : Cleaned the code a bit, you can remove the adding the last index part now.</p> <p>Edit 2:</p> <p>A possibly more elegant looking solution for this might be by removing the ncharcounter and using your splitting index for that. You can store the first value as '-1' if the first character is not ('/') or as ('0') if it is.</p> <pre><code> string strLine("/cd/desktop/../test/"); string strTempString; vector&lt;int&gt; splitIndices; vector&lt;string&gt; splitLine; int nLineSize = strLine.size(); // find indices splitIndices.push_back(-1); if(nLineSize!=0 &amp;&amp; strLine[0]=='/') { splitLine.push_back(strLine.substr(0,1)); splitIndices[0]=0; } for(int i = 1; i &lt; nLineSize; i++) { if(strLine[i] == '/') splitIndices.push_back(i); } // fill split lines for(int i = 1; i &lt;int(splitIndices.size()); i++) { strTempString = strLine.substr(splitIndices[i-1]+1, (splitIndices[i] - (splitIndices[i-1]+1) )); splitLine.push_back(strTempString); } </code></pre>
 

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