Hello,
I have a programming question... Suppose I have an std:: string with the contents "1,2,3,4,5"; and I want to convert it to 5 integer values.
One option is to use
Is there a C++ equivalent to do this?
I know I can convert a string to an integer using sstream:
But is there a way to split an std::string into tokens (similarly to strtok) ?
I seem to recall there is a way of specifying delimber chars for input streams, but don't remember....
Thanks!
Jörg
I have a programming question... Suppose I have an std:: string with the contents "1,2,3,4,5"; and I want to convert it to 5 integer values.
One option is to use
Code:
char buffer[80] strcpy (burffer, input.c_str()); char* token = strtok(buffer, ","); // strtok modifies the argument int a = atoi(token) char* token = strtok(null, ","); int b = atoi(token) ...
I know I can convert a string to an integer using sstream:
Code:
std::istringstream OutputStream(myString); int a; OutputStream >> a;
I seem to recall there is a way of specifying delimber chars for input streams, but don't remember....
Thanks!
Jörg
Comment