[学习笔记]C++17学习第7天
```# include <iostream>
# include <cctype>
// c++17
using namespace std;
int main()
{
char letter{};
cout << "Enter a letter: ";
cin >> letter;
int count{0};
if (isalpha(letter))
{
switch(auto lower{static_cast<char>(tolower(letter))}; lower)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
cout << "You entered a vowel.\n";
[];
default:
count ++;
break;
}
}
else
{
cout << "You didn't enter a letter.\n";
}
cout << "You entered " << count << " char(s)." << endl;
}
```
```
# include <iostream>
// c++17
using namespace std;
int main()
{
double rainfall[] {1.1, 2.8, 3.4, 3.7, 2.1, 2.3, 1.8, 0.0, 0.3, 0.9, 0.7, 0.5};
double copy)]{};
for (size_t i{}; i!= sizeof(rainfall)/sizeof(rainfall); ++i)
copy = rainfall;
for (size_t i{}; i!= sizeof(copy)/sizeof(copy); ++i)
cout << copy << ", ";
cout << endl;
}
```
```
# include <iostream>
# include <array>
// c++17
using namespace std;
int main()
{
int values[] {2,3,5,7,11,13,17,19,23,29};
for(size_t i{}; i!= size(values); ++i)
cout << values << ',';
cout << endl;
}
```
```
# include <iostream>
# include <iomanip>
# include <array>
// c++ 17
using namespace std;
int main()
{
constexpr double pi {3.14159265358979323846};
constexpr int perline{3};
int line_count {};
for (double radius{0.2}; radius < 10.0; radius += .2)
{
cout << fixed << setprecision(2) << "radisu=" <<setw(6) << radius << ", area=" << setw(8)<< pi*radius*radius;
if (++line_count%perline==0)
{
cout << endl;
}
else
{
cout << '\t';
}
}
}
```
坚持就是胜利,还有c++20标准
页:
[1]