Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) AskUserForDouble

 

AskUserForDouble is a std::string code snippet to ask the user for a single-line input (which is then converted to double).

 

 

 

 

 

 


#include <iostream>
#include <string>
#include <boost/lexical_cast.hpp>

//From http://www.richelbilderbeek.nl/CppAskUserForDouble.htm
const double AskUserForDouble()
{
  while (1)
  {
    const std::string s = AskUserForString();
    if (!IsDouble(s)) continue;
    return boost::lexical_cast<double>(s);
  }
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict