变量
C++基本数据类型
类型名 | 占用内存 | 精度 |
---|---|---|
short(short int) | 2字节 | - |
int | 4字节 | - |
long (long int) | 4字节 | - |
float | 4字节 | 7位 |
double | 8字节 | 15位 |
long double | 10字节 | 15位 |
char | 1字节 | - |
bool | 1字节 | - |
类型转换
- static_cast<*Type*><*Expression*> //常用
- const_cast<*Type*><*Expression*> //用于去除常量的const属性
- dynamic_cast<*Type*><*Expression*>
- reinterpret_cast<*Type*><*Expression*>
支持强制转换
浮点数的格式化输出
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(x); //x为小数点后显示位数的int值
科学计数法
3.67e17 表示\(3.67*10^{17}\)