

The empty() returns "true" if the vector is empty, otherwise, it returns "false." The clear() member function removes all of the elements of a vector and sets its size to 0. In the example, the size of "Scientist" is reduced from 4 to 3. The pop_back() removes the last element of a vector and reduces the vector size by one. As a result, Scientist is now equal to "James Maxwell", and Scientist is now equal to "Louis Pasteur". The push_back() adds a new element to the end of a vector. Std::cout << "You have something in the list\n" Scientist.push_back("Charles Augustin de Coulomb") įor (iter = Scientist.begin() iter != Scientist.end() ++iter) Using the push_back()/pop_back()/size()/clear()/empty() member function So, an algorithm has to be written only once to work with arbitrary containers because the iterator interface for iterators is common for all container types. They can search, sort, modify, or simply use the element for different purpose. The STL provides several standard algorithms for the processing of elements of collections. vector, string, and deque each provide random access iterators. These do everything bidirectional iterators do, but they also offer iterator arithmetic, i.e., the ability to jump forward or backward in a single step. The standard associative containers all offer bidirectional iterators. These are just like forward iterators, except they can go backward as well as forward. They don't support operator-, so they can move only forward. These have the capabilities of both input and output iterators, but they can read or write a single location repeatedly. The most common manifestation of output iterator is ostream_iterator. These are write-only iterators where each iterated location may be read only once. The most common manifestation of input iterator is istream_iterators. These are read-only iterators where each iterated location may be read only once. Iterators are divided into five groups, based on the operations they support. An iterator represents a certain position in a container. Iterators are objects that can navigate over elements. These include set, multiset, map, and multimap. These are sorted collections in which the actual position of an element depends on its value due to a sorting criterion. This position depends on the time and place of the insertion, but it is independent of the value of the element. These are ordered collections in which every element has a certain position. To meet different needs, the STL provides different kinds of containers. (popular templatized data structures), iterators and algorithms.Ĭontainers manage collection of element.

STL has three key components - containers
