1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
// stof example
#include <iostream> // std::cout
#include <string> // std::string, std::stof
int main ()
{
std::string orbits ("686.97 365.24");
std::string::size_type sz; // alias of size_t
float mars = std::stof (orbits,&sz);
float earth = std::stof (orbits.substr(sz));
std::cout << "One martian year takes " << (mars/earth) << " Earth years.\n";
return 0;
}
| |