string s, tmp; stringstream ss(s); vector<string> words; // If there is one element (so komma) then push the whole string if(getline(ss, tmp, ',').fail()) { words.push_back(s); } while(getline(ss, tmp, ',')){ words.push_back(tmp); }