Q:

C++ How do i make this vector function accept any delimiter

I got a question.
Previously on 1 of my quesion.
bitmask coded this:
std::vector<std::string> split(std::string const& str, std::string const& delimiters = ":") {
  std::vector<std::string> 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<std::string> split(std::string const& str, char const delimiter) {
  return split(str,std::string(1,delimiter));
}

And I use by this method:
vector<string> x = split(receiveClient, '#');

However as I realize the delimiter is fixed to #, at some point of time, I will need to use ":" or other delimiter for split string, so my question is, how do I change the function so it can accept delimiter I pass in.
such as
vector<string> x = split(receiveClient, ':');

Some issue I faced is "Segmentation core dump error"
The version that is not working
if(action=="auth")
{

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

    vector<string> check = split(sline, ':');

    logincheck = check[0] + ":" + check[3];
    cout << logincheck << endl;

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

    }
    myfile.close();

}

Running the above code get me error - Segmentation Core Dump
This is my account.txt file
admin:PeterSmite:hr:password
cktang:TangCK:normal:password

However if i change the code to my old version which don't use vector split, the code can run smoothly. Without segmentation core dump. the difference is the above use vector to split string sline into vector and then use it to assign to string logincheck
Working version(without vector split)
if(action=="auth")
{

 myfile.open("account.txt");
    while(!myfile.eof())
    {
        getline(myfile,sline);
    //action value is in form of like demo:pass (user input)
    if (sline==actionvalue)
    {
    sendClient = "login done#Successfully Login.";
    break;
    }
    else
    {
    sendClient = "fail login#Invalid username/password.";
    }

    }
    myfile.close();

}

My question is, how do i split it without segmentation core dump for the code with vector split 
 vector<string> check = split(sline, ':');

    logincheck = check[0] + ":" + check[3];
    cout << logincheck << endl;

A:

I'm just saying, you're reading the file wrong. eof() only returns true after you read the end of the file. The last line you are reading is empty (if you remembered to add a newline after the last data, like you should).
And you should check for empty strings that's in 90% the cause why poorly written code segfaults (when dealing with strings). And you should start using a debugger, like gdb to find out WHAT goes wrong instead of just posting the whole code.

