There is a third that you did not mention, istringstream , which you cannot use (well, you could, but it would be different, you cannot << to istringstream ).
stringstream is both ostringstream and istringstream - you can << and >> in both directions, in and out.
With ostringstream you can only log in with << , and you cannot log out with >> .
Actually there is no difference, you can use any way to convert strings to integers. If you want to do this as quickly as possible, I think boost::lexical_cast has this header, or you can use the itoa function, which may be faster than stringstream , but you lose the benefits of C ++ and the standard library if you use itoa (you should use C-lines, etc.).
In addition, as Benjamin Lindley told us, C ++ 11 has an std::to_string .
source share