-
创建项目
-
创建文件:源文件中添加新建项,在选中C++文件(.cpp)
-
编写代码
#includeusing namespace std; int main() { cout << "hello world" << endl; system("pause"); return 0; }
- 运行程序
- 单行注释
int main()//单行注释
- 多行注释
- 变量存在的意义:方便管理内存空间如将变量a指向某空间,操作时只需要使用a来操作,代替了16进制空间编号。
- 创建语法:数据类型 变量名=变量初始值
int a = 10;//创建变量1.4常量
- 用于记录程序中不可更改的数据
- 两种定义方法:
- (1)#define 常量名 常量值
- (2)const关键字修饰的变量(通常定义在函数体里面):const 数据类型 常量名 =常量值
#include1.5sizeof关键字using namespace std; #define day 7//宏常量 int main()//单行注释 { cout << "hello world" << endl; int a = 10;//创建变量 const int b = 5;//关键字修饰的变量 system("pause"); return 0; }
- 作用:统计数据类型/变量所占内存大小
- 语法:sizeof(数据类型/变量)
#include1.6C++输出语句endl与endsusing namespace std; #define day 7//宏常量 int main()//单行注释 { cout << "hello world" << endl; int a = 10;//创建变量 const int b = 5;//关键字修饰的变量 cout << "变量a所占内存大小:" << sizeof(a) << endl; system("pause"); return 0; }
- endl表示end of line此行输出结束并换行
- ends表示输出结束后空一格
#includeusing namespace std; #define day 7//宏常量 int main()//单行注释 { cout << "hello world" << ends;//输出结束空格 cout << "变量a所占内存大小:" << sizeof(a) << endl;//输出结束换行 int a = 10;//创建变量 const int b = 5;//关键字修饰的变量 system("pause"); return 0; }



