This is a prime example of where C++ code runs much slower than C code. My guess? Maybe 100 times slower, maybe 1000.
Consider what the C code would do.
1. You'd allocate a fixed length buffer on the stack. Cost zero.
2. Read the data into the string.
3. Call strtok to tokenize the string using a static context. Cost char comparison against each token character, plust writing NULL into the string and updating the context pointer.
4. print the value out.
Consider the C++ code:
1. Create a string object. Cost initially near zero, just a couple of values set (length and pointer).
2. Read the data into the string. Cost regrowing the target string to be large enough to hold the value, calls malloc possibly several times.
3. Create an istringstream from the string. These stringstream things have been shown to be expensive previously.
http://www.cplusplus.com/forum/general/74026/#msg396186
4. Create a vector of strings. Cost initially near zero, just a couple of values set (length and pointer).
5. Create another string to read from the istringstream. Cost initially near zero, just a couple of values set (length and pointer).
6. Read from istring stream into string until stream goes bad and append to vector.
This is a linear search thru the istream, checking against a list of delimiters.
Grows the target string, call to malloc eventually.
Appends the string to the vector, grows the vector logarithmicly, calling malloc and string copy constructors/destructors each time.