I would like to see if a string contains a double as its sole contents. In other words, if it could possibly be the output of the following function:
string
Or use streams directly:
#include
#include
#include
template
bool isValid(std::string const& num)
{
T value;
std::stringstream stream(num);
stream >> value;
// If the stream is already in the error state peak will not change it.
// Otherwise stream should be good and there should be no more data
// thus resulting in a peek returning an EOF
return (stream) &&
stream.peek() == std::char_traits::eof();
}
int main()
{
isValid("55");
}