C++ What is wrong with this Vector Splitting in While Loop
<p>This is my partial code:</p>

<pre><code>if(action=="auth")
{


 myfile.open("account.txt");
    while(!myfile.eof())
    {
        getline(myfile,sline);

        vector&lt;string&gt; y = split(sline, ':');
    logincheck = "";
    logincheck = y[0] + ":" + y[3];

    if (sline==actionvalue)
    {
    sendClient = "login done#Successfully Login.";
    break;
    }
    else
    {
    sendClient = "fail login#Invalid username/password.";
    }

    y.clear();
    }
    myfile.close();

}
</code></pre>

<p>If i don't have this </p>

<pre><code> logincheck = y[0] + ":" + y[3];
</code></pre>

<p>The code will not have any segmentation core dump error, but when I add that line, it will went totally wrong.</p>

<p>My account.txt is as followed:</p>

<pre><code>admin:PeterSmite:hr:password
cktang:TangCK:normal:password
</code></pre>

<p>The split function:</p>

<pre><code>std::vector&lt;std::string&gt; split(std::string const&amp; str, std::string const&amp; delimiters = "#") {
  std::vector&lt;std::string&gt; tokens;

  // 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);
  }
  return tokens;
}



std::vector&lt;std::string&gt; split(std::string const&amp; str, char const delimiter) {
  return split(str,std::string(1,delimiter));
}
</code></pre>
