1.操作步骤
首先打开visual Studio,选择新建项目,之后在源文件那里右键选择新建项,创建.cpp文件。
下面这个是很多程序都会有的固定框架:
#include<iostream>
using namespace std;
int main()
{
system("pause");
return 0;
}
接下来补充里面的内容:
#include<iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
system("pause");
return 0;
}
点击窗口上的本地windows调试器就可以运行这些代码了,会在屏幕中输出hello world。
2.注释
//注释内容
单行注释
/* 注释内容*/
多行注释
3.变量
作用:给一段指定的内存空间起名,方便操作这段内存
语法:数据类型 变量名 = 初始值;
int a = 10;
cout << "a=" << a << endl;
会输出a=10
4.常量
作用:用于记录程序中不可更改的数据
定义后的常量,一旦修改它的值,就会报错
定义方式:
①#define 常量名 常量值
定义宏常量,通常会在文件开头定义。定义后面都没有分号!!!
②const 数据类型 常量名 = 常量值;
用const修饰的变量
5.关键字
也叫标识符,在定义变量或者常量的时候,不要用关键字
asm | do | if | return | typedef |
---|---|---|---|---|
auto | double | inline | short | typeid |
bool | dynamic_cast | int | signed | typename |
break | else | long | sizeof | union |
case | enum | mutable | static | unsigned |
catch | explicit | namespace | static_cast | using |
char | export | new | struct | virtual |
class | extern | operator | switch | void |
const | false | private | template | volatile |
const_cast | float | protected | this | wchar_t |
continue | for | public | throw | while |
default | friend | register | true | |
delete | goto | reinterpret_cast | try |
标识符命名规则
1.标识符不能是关键字
2.标识符只能由字母、数字、下划线组成
3.第一个字符必须为字母或下划线
4.标识符中字母区分大小写