C++ examples for STL:vector
Use the capacity method to determine how many elements the vector is capable of storing before it will resize.
#include <cinttypes> #include <iostream> #include <vector> using namespace std; int main(int argc, char* argv[]) { vector<int32_t> stlVector{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; cout << "The size is: " << stlVector.size() << endl; cout << "The capacity is: " << stlVector.capacity() << endl; stlVector.emplace_back(17);//from w ww. j av a2 s . c om cout << "The size is: " << stlVector.size() << endl; cout << "The capacity is: " << stlVector.capacity() << endl; for (auto&& number : stlVector) { std::cout << number << std::endl; } return 0; }