记录下b站黑马程序员的c++教程学习过程,就当是我的赛博笔记了
在vscode中装载了c/c++,完成了.jason文件的配置
1.C++初识
- c++代码在书写时,总可以从下面代码开始:
#include <iostream>
using namespace std;
int main()
{
system("pause");
return 0;
}
书写helloworld代码:
cout << "hello world" << endl
开始编译,虽然已经完成环境配置,还会存在问题:终端的输出会重复很多遍
该问题还有待解决
注释:
//单行注释
/*多行注释
可以换行*/
- 变量创建:方便管理内存空间
变量类型+变量名 = 变量初始值
int a = 10
cout << "a=" << a << endl
输出:a=10
- 常量创建:用于记录程序中不能更改的数据
宏常量:#define 变量名 变量值 (一般在文件最上方)
const修饰的变量:const 数据类型 变量名 = 变量值
#include<iostream>
using namespace std;
#define Day 7
int main(){
const int Month = 12;
cout << "there are " << Day << "days in one week" << endl;
cout << "there are " << Month << "months in one year" << endl;
pause<system>;
return 0;
}
输出:there are 7 days in one week
there are 12 months in one year
- c++中的关键字
没必要一个个记,在给变量或常量起名时不能用关键字
- 标识符命名规则
- 标识符不能是关键字
- 标识符只能包括字母、数字、下划线
- 标识符只能以字母、下划线开头
- 标识符区分大小写