Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 532 Bytes

reserve.md

File metadata and controls

24 lines (18 loc) · 532 Bytes

reserve

Description :

  • Helps specify the minimum size of a vector
  • Useful to know how many elements the vector will ultimately hold

Example:

	//create an empty vector
        std::vector<int> myvector;

        //reserve a size of 'atleast' 5 elements
        myvector.reserve(5);

        //inserting 5 elements
        for(int i=0; i<5; i++)
        {
                myvector.push_back(i);
        }

See sample code Run Code