1. Boolean type
#include <iostream>
int main()
{
bool isAlpha;
isAlpha = false;
if (!isAlpha)
{
std::cout << "isAlpha=" << isAlpha << std::endl;
std::cout << std::boolalpha <<
"isAlpha=" << isAlpha << std::endl;
}
return 0;
}
The boolean type only contains two values, 0 and 1, std::boolalpha is used to make the output in English (1 becomes true, 2 becomes false)
2. List initialization and forced type conversion
#include <iostream>
int main()
{
//列表初始化不允许窄化
int x{
1 };
std::cout << x << std::endl;
//强制类型转换 :int ->double;double->int
std::cout << 1 / 2 << std::endl;
std::cout << static_cast<double>(1) / 2 << std::endl;
std::cout << static_cast<double>(1 / 2) << std::endl;
std::cout << 1.0f / 2.f << std::endl;
std::cin.get();
return 0;
}
Get the result shown above.