capacity() – it returns the current capacity of the vector.max_size() – returns the maximum size the vector can hold.crend() – it refers to the theoretical element before the first element of the vector.crbegin() – it refers to the last element of the vector.rend() – it points to the theoretical element before the first element of the vector.rbegin() – it points to the last element of the vector. cend() – it refers to the theoretical element after the last element of the vector.cbegin() – it refers to the first element of the vector.Size of the vector after clearing the vector: 0 Printing the vector after removing the last element: The elements in the vector: 0 1 2 3 4 5 6 7 8 9 V.push_back(i) //inserting elements in the vectorįor (auto it = v.begin() it != v.end() it )Ĭout << "\nThe front element of the vector: " << v.front() Ĭout << "\nThe last element of the vector: " << v.back() Ĭout << "\nThe size of the vector: " << v.size() Ĭout << "\nDeleting element from the end: " << v Ĭout << "\nPrinting the vector after removing the last element:" << endl Ĭout << "\nInserting 5 at the beginning:" << endl Ĭout << "The first element is: " << v << endl Ĭout << "Erasing the first element" << endl Ĭout << "Now the first element is: " << v << endl Ĭout << "Size of the vector after clearing the vector: " << v.size() size() – returns the size of the vector.empty() – to check if the vector is empty or not.clear() – deletes all the elements from the vector.back() – it returns a reference to the last element of the vector.front() – it returns a reference to the first element of the vector.pop_back() – it deletes the last element and returns it to the calling function.V1.erase(it) // erasing the first element erase() – it is used to delete a specific element. V1.insert(it,5) //inserting 5 at the beginning
0 Comments
Leave a Reply. |