实型(浮点型)
作用:用于表示小数
单精度:float;双精度:double
字符型
作用:用于显示单个字符
语法:char ch = ‘a'; ( 使用单引号将字符括起来,且只能写一个字符)
#include <iostream>
using namespace std;
int main() {
char ch = 'a';
char ch2 = 'A';
cout << ch << endl;
cout << "ch占用的内存空间为" << sizeof(ch) <<"个字节" << endl;
//字符型变量对应的ASCII编码
cout <<"a对应的ASCII编码是" << int(ch) << endl;//a - 97
cout << "A对应的ASCII编码是" << int(ch2) << endl;//A - 65
system("pause");
return 0;
}
字符串类型
作用:用于表示一串字符
#include <iostream>
#include <string>
using namespace std;
int main() {
//C风格字符串
char str[] = "hello world";
cout << str << endl;
//C++风格字符串
//需要添加头文件
string str2 = "hello world";
cout << str2 << endl;
system("pause");
return 0;
}
转义字符
作用:用于表示一些不能显示出的ASCII编码
#include <iostream>
using namespace std;
int main() {
//换行符 \n
cout << "hello world\n";
//反斜杠 \\
cout << "\\" << endl;
//水平制表符 \t
cout << "aaa\thelloworld"<
布尔类型 bool
作用:代表真或假的值
bool类型只有两个值,即 真(1)与假(0)
#include <iostream>
using namespace std;
int main() {
//本质上 1 代表真,0 代表假
bool flag = true;
cout << flag << endl;
flag = false;
cout << flag << endl;
//bool类型所占内存空间为1
cout << "size of bool is " << sizeof(flag) <<" byte"<< endl;
system("pause");
return 0;
}

Comments NOTHING