zoukankan      html  css  js  c++  java
  • vector

    ////////////////////////////////////////
    //      2018/04/15 19:12:27
    //      vector - capacity(容量)
    
    /*
     Size指目前容器中实际有多少元素,对应的resize(size_type)会在容器尾添加或删除一些元素,
     来调整容器中实际的内容,使容器达到指定的大小。
    
     Capacity指最少要多少元素才会使其容量重新分配,对应reserve(size_type new_size)
     会这置这个capacity值,使它不小于所指定的new_size。
    
        故用reserve(size_type)只是扩大capacity值,这些内存空间可能还是“野”的,如果此时使用"[ ]"来
    访问,则可能会越界。而resize(size_type new_size)会真正使容器具有new_size个对象。
    */
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    int main(){
        vector<int> v(10);
    
        cout << "Size of v = " << v.size() << endl;
        cout << "Capacity of v =" << v.capacity() << endl;
    
        v.resize(100);
    
        cout << "After resizing:" << endl;
        cout << "Size of v = " << v.size() << endl;
        cout << "Capacity of v = " << v.capacity() << endl;
    
        return 0;
    }
    /*
    OUTPUT:
        Size of v = 10
        Capacity of v =10
        After resizing:
        Size of v = 100
        Capacity of v = 100
    */ 
  • 相关阅读:
    linux升级node版本
    mysql视图
    mysql全文本搜索
    mysql数据处理函数
    mysql数据分组
    mysql组合查询
    Django添加生产环境配置
    费用保险单,如何失焦时自动补零
    div+css滚动条
    phpadmin导入数据提示文件最大限制的修改方法
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538053.html
Copyright © 2011-2022 走看看