1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// ratio example
#include <iostream>
#include <ratio>
int main ()
{
typedef std::ratio<1,3> one_third;
typedef std::ratio<2,4> two_fourths;
std::cout << "one_third= " << one_third::num << "/" << one_third::den << std::endl;
std::cout << "two_fourths= " << two_fourths::num << "/" << two_fourths::den << std::endl;
typedef std::ratio_add<one_third,two_fourths> sum;
std::cout << "sum= " << sum::num << "/" << sum::den;
std::cout << " (which is: " << ( double(sum::num) / sum::den ) << ")" << std::endl;
std::cout << "1 kilogram has " << ( std::kilo::num / std::kilo::den ) << " grams";
std::cout << std::endl;
return 0;
}
|