C++之起航篇

来源:互联网 发布:telnet端口不通原因 编辑:程序博客网 时间:2024/05/20 05:58

1.应用领域

嵌入式游戏网络系统

2.诞生地

贝尔实验

3.特点

速度快内存省

4.C++和C的关系

C语言是C++的子集C++是在C面向过程的基础上增添了面向对象

5.常用IDE

VSCB

6.新的数据类型

比较与C语言,新增了bool,逻辑类型

7.新的初始化方法

C:赋值初始化,int x = 1024;C++:赋值初始化,int x = 1024; 直接初始化:int x(1024);

8.输入输出方式

C:scanf/printfC++:cin/cout好处:不用关注占位符     不用关注数据类型     不易出现问题Demo:    #include <iostream>    using namespace std;    int main() {        cout << "请输入一个整数:" << endl;        int x = 0;        cin >> x;        cout << oct << x << endl;        cout << dec << x << endl;        cout << hex << x << endl;        cout << "请输入一个布尔值(0、1):" << endl;        bool y = false;        cin >> y;        cout << boolalpha << y << endl;        return 0;    }

9.命名空间

就是划片取名字,避免命名冲突Demo:    #include <iostream>    using namespace std;    namespace A {        int x = 1;        void fun() {            cout << "A" << std::endl;        }    }    namespace B {        int x = 2;        void fun() {            cout << "B" << endl;        }        void fun2() {            cout << "2B" << endl;        }    }    using namespace B;    int main() {        cout << A::x << endl;        A::fun();        fun2();    }

10.以上的综合小Demo

#include <iostream>using namespace std;namespace compA {    int getMaxOrMin(int* arr, int count, bool isMax) {        int temp = arr[0];        for (int i = 1; i < count; i++) {            if (isMax) {                if (temp < arr[i]) {                    temp = arr[i];                }            } else {                if (temp > arr[i]) {                    temp = arr[i];                }            }        }        return temp;    }}
1 0
原创粉丝点击