double stod (const string& str, size_t* idx = 0);double stod (const wstring& str, size_t* idx = 0);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// stod example
#include <iostream> // std::cout
#include <string> // std::string, std::stod
int main ()
{
std::string orbits ("365.24 29.53");
std::string::size_type sz; // alias of size_t
double earth = std::stod (orbits,&sz);
double moon = std::stod (orbits.substr(sz));
std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n";
return 0;
}
The moon completes 12.3684 orbits per Earth year.