#include <iostream>
#include <vector>

using namespace std;

/*
 * 结论:
 * capacity = 1, newcapacity = 2;
 * capacity > 1, newcapacity = (int)(capacity * 1.5);
 */
int main(){
    int cap = -1;
    vector<int> ints;
    for(int i = 0;i<1000000;i++){
        ints.push_back(i);
        if( cap != ints.capacity()){
            cap = ints.capacity();
            cout << " ints.size() = " << ints.size() << "  ints.capacity() = " << cap << endl;
        }
    }
    cout << (int)(3*1.5) << endl;
    system("pause");
    return 0;
}

 

相关文章:

  • 2021-06-09
  • 2021-09-08
  • 2021-12-21
  • 2021-04-06
  • 2021-04-27
猜你喜欢
  • 2022-01-17
  • 2022-02-26
  • 2021-12-25
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案