1.字符串定义方式
char str[] ="hello world";
cout << str << endl;
string str1 = "Hi C++ learner";
cout << str1 << endl;
#include <string> 有时需要。 VS2019不需要这个头文件也能使用string这个类型。
2. Bool类型占空间大小
bool flag = true;
cout << flag << endl; // 1
flag = false;
cout << flag << endl; // 0
cout << "size of bool = " << sizeof(bool) << endl; //1
3.数据的输入
//整型输入
int a = 0;
cout << "请输入整型变量:" << endl;
cin >> a;
cout << a << endl;
4.算术运算
- / 除 10 / 5 2
- % 取模(取余) 10 % 3 1
- ++ 前置递增 a=2; b=++a; a=3; b=3