More about Vector

来源:互联网 发布:网络监控摄像头ip地址 编辑:程序博客网 时间:2024/05/28 16:22

1. Vector Constructor

vector<int> myVector;vector<long> myVector(elementNo);vector<float> myVector(elementNo, value);

2. Accessing elements of a vector

//safe access version, check boundsmyVector.at(index);//unsafe access versionmyVector[index];  // not check bounds


3. Vector property

myVictor.size();   //returns the number of elements in myVector;myVictor.capacity() //returns how much myVictor can hold;myVictor.max_size(); returns the maximum number of elements the container can hold. it determined by system. 

4. Insert/Delete elements

myVector.push_back(const TYPE& val);//adding a single element to the end of a vector.myVector.pop_back(); //remove a single element from the end of a vector


0 0
原创粉丝点击