Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) ReadDoubleFromFile

 

File I/O code snippets to read the first line of a file and convert it to a double.

 

///ReadDoubleFromFile reads the first line of a file
///and converts it to a double.
///From http://www.richelbilderbeek.nl/CppReadDoubleFromFile.htm
double ReadDoubleFromFile(const std::string& fileName)
{
  const std::vector<std::string> v = FileToVector(fileName);
  assert(v.empty()==false);
  const double d = std::atof(v[0].c_str());
  return d;
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict