Possible Duplicate:
How do I tokenize a string in C++?
Hello I was wondering how I would tokenize a std string with strtok
string line = "hello, world, bye";
char * pch = strtok(line.c_str(),",");
I get the following error
error: invalid conversion from ‘const char*’ to ‘char*’
error: initializing argument 1 of ‘char* strtok(char*, const char*)’
I'm looking for a quick and easy approach to this as I don't think it requires much time
I always use getline
for such tasks.
istringstream is(line);
string part;
while (getline(is, part, ','))
cout << part << endl;