(C++) std::istringstream
January 8, 2018 · View on GitHub
(C++) std::istringstream
std::istringstream is an STL input stream data type.
Example: IsDouble
The example below shows how to check if a std::string can be converted to double: put the std::string in an std::istringstream and try to write it to a double. If this fails, the std::string cannot be converted to double.
#include <cassert> #include <sstream> //From http://www.richelbilderbeek.nl/CppIsDouble.htm bool IsDouble(const std::string& s) { std::istringstream i(s); double temp; return ( (i >> temp) ? true : false ); }