Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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 );
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict