[学习笔记]C++17学习第3天
本帖最后由 mdl2999_52pj 于 2021-5-18 10:03 编辑```
#include <iostream>
// c++ 17
using namespace std;
int main()
{
// 浮点数
constexpr double pi {3.141592653589793};
double a{.2};
double z{9};
double volume {pi *z*z *a};
cout << "volume = " <<volume << endl;
}
```
```
# include <iostream>
# include <cmath>
// c++ 17
using namespace std;
int main()
{
// 无效的浮点结果
double a{1.5}, b{}, c{};
// 无穷大
cout << a << "/" << b << " = " << a/b << endl;
// 无穷
cout << a << "/" << b << " + " << c << " = " << a/b + c << endl;
// 非数字
cout << b/c << endl;
cout << isnan(b/c) <<endl;
cout << isinf(a/b) << endl;
}
```
```
# include <iostream>
# include <iomanip>
// c++ 17
using namespace std;
int main()
{
constexpr double pi {3.141592653589793 };
cout << "[" << setprecision(10) <<setw(20) << pi << "]" << endl;
cout << "[" << setprecision(10) <<setw(20) << scientific << pi << "]" << endl;
cout << "[" << showbase << hex << 1'0000'0000 << "]" << endl;
}
```
赞一个 赞一个
页:
[1]