[学习笔记]C++17学习第5天
```# include <iostream>
// c++ 17
using namespace std;
int main()
{
// 运算优先级 略
// 位运算
unsigned short number {16387};
auto result { static_cast<unsigned short>(number << 2)} ;
cout << "number = " << number << " number << 2 = " << result << endl;
number = 16387;
cout << "number = " << number ;
number >>= 2;
cout << " number >> 2 = " << number << endl;
number = 16387;
cout << "number << 2 = " << (number<<2) << endl;
}
```
```
# include <iostream>
// c++17
using namespace std;
int main()
{
//位运算
// 字体
//00000110 0 1 0 01100
//样式=6 未使用 斜体非粗体点数=12
unsigned short font {0b00'000'110'0'10'01100};//
unsigned short size_mask {0b11111};
unsigned short style_mask {0xff00};
auto size { static_cast<unsigned short>( font & size_mask ) };
auto style{ static_cast<unsigned short>( (font & style_mask)>>8 ) };
cout << "font size = " << size << endl;
cout << "font style = " << style << endl;
auto bold {static_cast<unsigned short>(1U<<5)};// 粗体
auto italic {static_cast<unsigned short>(1U<<6)}; // 斜体
cout << "font bold = " << (font & bold) << endl;
cout << "font italic = " << (font & italic) << endl;
// 设置粗体
font |= bold;
// 清楚斜体
font &= ~italic;
cout << "font bold = " << (font & bold) << endl;
cout << "font italic = " << (font & italic) << endl;
}
```
楼主今天这段代码还是比简单的,楼主加油 ```
# include <iostream>
# include <iomanip>
// c++17
using namespace std;
int main()
{
//枚举类型
enum class Day {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
Day yesterday {Day::Monday}, today {Day::Tuesday}, tomorrow{Day::Wednesday};
const Day poets_day {Day::Friday};
enum class Punctuation : char {Comma=',', Exclamation='!', Question='?'};
Punctuationch {Punctuation::Comma};
cout << "Yesterday's value is " << static_cast<int>(yesterday)
<< static_cast<char>(ch) << " but poets day's is " << static_cast<int>(poets_day)
<< static_cast<char>(Punctuation::Exclamation) << endl;
today = Day::Thursday;
ch = Punctuation::Question;
tomorrow = poets_day;
cout << "Is today's value(" <<static_cast<int>(today) << ") the same as poets_day("
<<static_cast<int>(poets_day) << ')' << static_cast<char>(ch) << endl;
cout << static_cast<int>(tomorrow) << endl;
}
```
```
# include <iostream>
// c++17
using namespace std;
int main()
{
// 练习题,提示输入两个整数,存储在a和b中,
// 不使用第三个变量,交换两个数的值,并输出
cout << "Enter two integers:";
int a,b;
cin >> a >> b;
cout << "a = " << a << " and b = " << b << endl;
a = a^b;
b = a^b;
a = a^b;
cout << "Now swap(a,b)\n";
cout << "a = " << a << " and b = " << b << endl;
}
```
```
# include <iostream>
# include <cctype>
// c++17
using namespace std;
int main()
{
char letter{};
cout << "Enter a letter: ";
cin >> letter;
if (isupper(letter))
cout << "You entered an uppercase letter.\n";
else if (islower(letter))
cout << "You entered a lowercase letter.\n";
else
cout << "You dit not enter a letter.\n";
}
```
唉 c++是最基础的,楼主加油啊
页:
[1]