zoukankan      html  css  js  c++  java
  • STL 六大部件

    stl具有上面6大部件

    容器是存储数据的,原理主要是模板,容器只是负责存储数据,并不关心内存的存储情况,所以出现了分配器,分配器主要是负责为容器分配内存的,对于数据的操作被封装为一个个函数,也就是算法,算法就是利用一些数据结构实现对数据的各种操作,算法和容器的连接就是通过迭代器实现的,迭代器实质就是一个指针,仿函数(functor),就是使一个类的使用看上去像一个函数。其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了。适配器就是一个接口

     

    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<vector>
    using namespace std;
    int main(){
        int a[6]={1,3,5,7,9,11};
        vector<int,allocator<int>>vv(a,a+6);
        cout<<count_if(vv.begin(),vv.end(),not1(bind2nd(less<int>(),5)))<<endl;
        //cout:4
        
        return 0;
    }
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    #include<functional>
    #include<vector>
    using namespace std;
    int main(){
        int a[6]={1,3,5,7,9,11};
        vector<int,allocator<int>>ar(a,a+6);
        
        //vector<int,allocator<int>>::iterator iter;
        //auto代替了上面一行
        auto iter =::find(ar.begin(),ar.end(),5);
        cout<<*iter<<endl;
        
        
        return 0;
    }
  • 相关阅读:
    C++ 编码转换
    获取文件扩展名
    字符串分割(C++)(转载)
    Visual Leak Detector简明使用教程
    Win32 文件拖拽
    IMAP协议命令(详细)
    CreateDirectory 创建文件夹 CC++
    编程习惯总结
    GitHub上整理的一些工具,求补充
    jquery生成qrcode二维码
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6385903.html
Copyright © 2011-2022 走看看