用户定义的文字,具有长双精度值
#include <iostream>
long double operator"" _km(long double val)
{
return val * 1000.0;
}
long double operator"" _mi(long double val)
{
return val * 1609.344;
}
int main()
{
std::cout << "3 km = " << 3.0_km << " m\n";
std::cout << "3 mi = " << 3.0_mi << " m\n";
return 0;
}
该程序的输出如下:
3 km = 3000 m
3 mi = 4828.03 m