Following is how I am using string tokenizer.
typedef std::string string_t;
typedef std::vector<string_t> stations_t;
void Tokenize(const string_t& str, stations_t& tokens,const string_t& delimiters = " ") {
string_t::size_type lastPos = str.find_first_not_of(delimiters, 0);
string_t::size_type pos = str.find_first_of(delimiters, lastPos);
while (string_t::npos != pos || string_t::npos != lastPos){
tokens.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
}
When I am passing string 1,8003,1,HWH,Kolkata Howrah Junction,,16:10,,1,0
to this , it is returning me 8
fields, where as it should return 9
, it is complete ignoring ,,
part. Can anybody pls take a look and help me to find the bug here.