piece of code stl (2)

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


using namespace std;


int main()
{
        long i= (long)9000*1000;
        vector<int> iv(2, 9);
//      for(long j = 0; j< 2000; j++){
//              iv.push_back(j+1000);
//      }
/*
        for(int k = 0; j < 20000000000+2; j++){


        }
*/
        iv.assign(2000, 999999);
        cout << "After assign(),    iv.size() == " << iv.size() << ", iv.capacity() == " << iv.capacity() << endl;
        int val = 999;
        iv.resize(i, val);
        cout << "After resize(),    iv.size() == " << iv.size() << ", iv.capacity() == " << iv.capacity() << endl;
//      cout << "The value of 2000 000 000 000 -1 = " << iv[i-1] << endl;
        for(int k = 0; k < 200000; k++){
                iv.pop_back();
        }
        cout << "After pop_bakup(), iv.size() == " << iv.size() << ", iv.capacity() == " << iv.capacity() << endl;
        iv.clear();
        cout << "After clear(),     iv.size() == " << iv.size() << ", iv.capacity() == " << iv.capacity() << endl;
        return 0;

}


================================================================================================================================================

After assign(),    iv.size() == 2000, iv.capacity() == 2000
After resize(),    iv.size() == 9000000, iv.capacity() == 9000000
After pop_bakup(), iv.size() == 8800000, iv.capacity() == 9000000
After clear(),     iv.size() == 0, iv.capacity() == 9000000

你可能感兴趣的:(piece of code stl (2))