#include #include #include #include using namespace std; string *explode(string input, string delimiter, int count=0) { int counting = 0; string::size_type countloc = 0; string::size_type countpos = 0; while (countloc != string::npos) { counting++; countloc = input.find(delimiter, countpos); countpos = countloc +1; } if (count != 0 && counting > count) counting = count; string *result = new string[counting]; string::size_type pos = 0; string::size_type loc = 0; int iterator = 0; while (loc != string::npos) { loc = input.find(delimiter, pos); result[iterator] = input.substr(pos, (loc - pos)); pos = loc +1; iterator++; } return result; } int main() { string *foo = explode("this is a test", " "); cout << "1=>" << foo[0] << "\n"; cout << "2=>" << foo[1] << "\n"; cout << "3=>" << foo[2] << "\n"; cout << "4=>" << foo[3] << "\n"; cin.get(); }