mdl2999_52pj 发表于 2021-5-16 10:35

[学习笔记]C++17学习第4天

```
# include <iostream>
// c++17
using namespace std;

int main()
{
        //类型转换
        double v1 {10.9};
        double v2 {15.9};
       
        int t1 {static_cast<int>(v1) + static_cast<int>(v2)};
        int t2 {static_cast<int>(v1+v2)};
       
        cout << v1 << ", " << v1 << ", " << t1 << ", " << t2 ;
}
```

mdl2999_52pj 发表于 2021-5-16 10:48

```
# include <iostream>
# include <limits>
//c++17
using namespace std;

int main()
{
        cout << "The range for type short is from " << std::numeric_limits<short>::min() << " to "
                <<std::numeric_limits<short>::max() << endl;
               
        cout << "The range for type int is from " << std::numeric_limits<int>::min() << " to "
                <<std::numeric_limits<int>::max() << endl;
               
        cout << "The range for type long is from " << std::numeric_limits<long>::min() << " to "
                        <<std::numeric_limits<long>::max() << endl;
                       
        cout << "The range for type float is from " << std::numeric_limits<float>::min() << " to "
                        <<std::numeric_limits<float>::max() << endl;
                       
        cout << "The range for type float is from " << std::numeric_limits<float>::lowest() << " to "
                        <<std::numeric_limits<float>::max() << endl;
                               
        cout << "The range for type double is from " << std::numeric_limits<double>::min() << " to "
                        <<std::numeric_limits<double>::max() << endl;
                               
        cout << "The range for type double is from " << std::numeric_limits<double>::lowest() << " to "
                        <<std::numeric_limits<double>::max() << endl;
       
        cout << "The range for type long double is from " << std::numeric_limits<long double>::min() << " to "
                        <<std::numeric_limits<long double>::max() << endl;
                                       
        cout << "The range for type long double is from " << std::numeric_limits<long double>::lowest() << " to "
                        <<std::numeric_limits<long double>::max() << endl;
                                                               
                       
}
```

she383536296 发表于 2021-5-16 10:49

可以,希望你有耐心坚持下去

mdl2999_52pj 发表于 2021-5-16 10:55

```
# include <iostream>
//c++17
using namespace std;

int main()
{
        //字符变量
        char ch{'A'};
        ++ch;
        cout << "ch is '" << ch << "' which is code " << hex << showbase << static_cast<int>(ch) << endl;
}
```

mdl2999_52pj 发表于 2021-5-16 11:17

```
# include <iostream>
//c++17
using namespace std;

int main()
{
        //auto 单值初始化
        auto m{10}; // int
        auto n{200UL}; // unsigned long int
        auto pi{3.14159}; // double
       
        cout << m << n << pi << endl;
       
        auto v1 = {3.14159}; // std::initializer_list<double>
        auto v2 = {3,4,5}; // std::initializer_list<int>
       
        for (auto x:v1)
                cout << x ;
    cout << endl;
    for (auto x:v2)
            cout << x;
    cout << endl;
}
```

致远英才 发表于 2021-5-16 11:43

加油!好好学习天天向上

alan3258 发表于 2021-5-16 11:59

请问用的什么IDE开发的?

tlf 发表于 2021-5-16 13:13

mdl2999_52pj 发表于 2021-5-16 13:59

alan3258 发表于 2021-5-16 11:59
请问用的什么IDE开发的?

red panda dev c++
页: [1]
查看完整版本: [学习笔记]C++17学习第4天