[1]序章,基本

(1)标准库>STL

  • C++标准库header files不带副档名(.h)
    #inlude <vector>
  • 旧式的C header files 仍然可用
  • 命名空间 namspace “std” 封装起来。
    新式headers的组件都封装在namespace “std”里面。
    旧式不封装于 namespace “std”

    这里有个小Tip(来自cherno的习惯,尽可能不使用using namespace 等等,以及,绝不在头文件里使用,因为EA里面有一个自己写的STL。)

(2)STL六大部件

容器(containers)、分配器(Allocators)、算法(Alogorithms)、迭代器(Iterators)、适配器(Adapters)、仿函数(Functors)

#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

int main()
{
  int ia[6] = {1,2,3,4,5,6};
  vector<int,allocator<int>> vi(ia,ia+6);

  cout << count_if(vi.begin(),vi.end(),
                   notl(bind2nd(less<int>(),40)));

  return 0;
}

//vector 是容器,第二个参数是分配器(allocator)不写也可以,会自动去分配内存。
//vi.end() 迭代器
//count_if 算法 bind2nd 适配器 less仿函数

(3)复杂度

(4)前闭后开区间

 

 拿不到*c.end(),不属于容器内。注意,方框里是遍历的写法,更先进的写法

 

posted @ 2020-03-25 15:52  新叽  阅读(149)  评论(0编辑  收藏  举报