I'm not a C++ guru, but for what they are worth, I have some comments:
it would be better to evaluate s.end() just once (outside the loop). Correction: this won't help.
the function fails if
sstarts with a spaceyou have duplicate code turning an int into a string. Perhaps use C++11
to_stringor write your own a function, such as:template <typename T> static std::string to_string(T num) { std::stringstream ss; ss << num; return ss.str(); }