1.使用命名空间using namespace std;
extern
这个是全局变量声明extern关键字的全局变量和函数可以使得它们能够跨文件被访问。
我也不知道有啥用,用这个和不用这个的效果没什么区别~~~
常量
85         // 十进制
0213       // 八进制 
0x4b       // 十六进制 
30         // 整数 
30u        // 无符号整数 
30l        // 长整数 
30ul       // 无符号长整数
//浮点类型的常量
3.14159       // 合法的 
314159E-5L    // 合法的 
510E          // 非法的:不完整的指数
210f          // 非法的:没有小数或指数
.e55          // 非法的:缺少整数或分数转义字符

define定义内容
#include <iostream>
using namespace std;
 
#define LENGTH 10   
#define WIDTH  5
#define NEWLINE \\'\n\\'
int main()
{
 
   int area;  
   
   area = LENGTH * WIDTH;
   cout << area;
   cout << NEWLINE;
   return 0;
}常量
const int  LENGTH = 10;修饰符
short int i;           // 有符号短整数
short unsigned int j;  // 无符号短整数静态变量
这个可以起到存储的作用,比如下面这个例子
int main()
{
    while(count--)
    {
        func();
    }
    return 0;
}
// 函数定义
void func( void )
{
    static int i = 5; // 局部静态变量
    i++;
    std::cout << "变量 i 为 " << i ;
    std::cout << " , 变量 count 为 " << count << std::endl;
}
//输出结果
变量 i 为 6 , 变量 count 为 9
变量 i 为 7 , 变量 count 为 8
变量 i 为 8 , 变量 count 为 7
变量 i 为 9 , 变量 count 为 6
变量 i 为 10 , 变量 count 为 5
变量 i 为 11 , 变量 count 为 4
变量 i 为 12 , 变量 count 为 3
变量 i 为 13 , 变量 count 为 2
变量 i 为 14 , 变量 count 为 1
变量 i 为 15 , 变量 count 为 0运算符
一些简单的包括逻辑运算我这里不讲,这里说一下位运算
int a = 60;      // 60 = 0011 1100
int b = 13;      // 13 = 0000 1101
int c=0;
c = a & b;                // 12 = 0000 1100(与运算
c = a | b;             // 61 = 0011 1101(或运算
c = a ^ b;             // 49 = 0011 0001 (异或操作
c = ~a;                // -61 = 1100 0011(翻转
c = a << 2;            // 240 = 1111 00004(左移运算
c = a >> 2;            // 15 = 0000 1111(右移运算杂项运算符

函数
函数传值可以设置默认值
#include <iostream>
using namespace std;
 
int sum(int a, int b=20)
{
  int result;
 
  result = a + b;
  
  return (result);
}
 
int main ()
{
   // 局部变量声明
   int a = 100;
   int b = 200;
   int result;
 
   // 调用函数来添加值
   result = sum(a, b);
   cout << "Total value is :" << result << endl;
 
   // 再次调用函数
   result = sum(a);
   cout << "Total value is :" << result << endl;
 
   return 0;
}Lambda 函数与表达式
参考https://www.cnblogs.com/DswCnblog/p/5629165.html
默认格式[capture list] (params list) mutable exception-> return type { function body }
capture list:捕获外部变量列表
params list:形参列表
mutable指示符:用来说用是否可以修改捕获的变量
exception:异常设定
return type:返回类型
function body:函数体
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
    return  a < b;
}
int main()
{
    vector<int> myvec{ 3, 2, 5, 7, 3, 2 };
    vector<int> lbvec(myvec);
    sort(myvec.begin(), myvec.end(), cmp); // 旧式做法
    cout << "predicate function:" << endl;
    for (int it : myvec)
        cout << it << \' \';
    cout << endl;
    sort(lbvec.begin(), lbvec.end(), [](int a, int b) -> bool { return a < b; });   // Lambda表达式
    cout << "lambda expression:" << endl;
    for (int it : lbvec)
        cout << it << \' \';
}值的捕获
int main()
{
    int a = 123;
    auto f = [&a] { cout << a << endl; }; 
    a = 321;
    f(); // 输出:321
}传递参数
cout << "n:" << [](int x, int y) { return x + y; }(5, 4) << std::endl;            //输出n:9数学运算

// 设置种子
srand(time(NULL));
//生成随机数
cout << rand();数组
//c++数组
int a[5]={1,2,3,4,5};
cout << a[0]<<endl;
int b[5];
b[1]=5;
//其他的如果没有初始化就会生成一个随机数
cout << b[1]<<"|"<<b[2];
//输出结果
1
5|1975897280指向指针的数组(使用两种方法遍历数组)
int main ()
{
   // 带有 5 个元素的双精度浮点型数组
   double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};
   double *p;
 
   p = balance;
 
   // 输出数组中每个元素的值
   cout << "使用指针的数组值 " << endl; 
   for ( int i = 0; i < 5; i++ )
   {
       cout << "*(p + " << i << ") : ";
       cout << *(p + i) << endl;
   }
 
   cout << "使用 balance 作为地址的数组值 " << endl;
   for ( int i = 0; i < 5; i++ )
   {
       cout << "*(balance + " << i << ") : ";
       cout << *(balance + i) << endl;
   }
 
   return 0;
}给函数传递数组
void print(int *p){
    cout << p<<endl; //输出这个数组的地址
    cout << &p[0]<<endl; //输出这个数组的地址(和上面这个是一样的
    cout << p[1]<<endl; //输出2
}
void print2(int a[5]){
    cout << a[1]<<endl;//输出2
}
void print3(int a[]){
    cout << a[1]<<endl;//输出2
}
int main()
{
    int a[5]={1,2,3,4,5};
    print(a);
    print2(a);
    print3(a);
}字符串
//下面这个三个输出的结果是一样的
char a1[6]= {\'h\', \'e\',\'l\',\'l\',\'o\',\'\0\'}; //结尾一定要加\0要不然会输出类似hello?@
char a3[6]= "hello";
char a4[]= "hello";//数字可以不加字符串函数

 
                     
                     
                        
                        