s
Start Teaching
Messages
User
Back to Stories
Standard Template Library in C++
Technology
Academics & Languages
  • Apr 16, 2021
  • 1 minute

PREMIUM
 Standard Template Library in C++

Need of STL?

When we develop some applications we have to deal with data. The data is a collection of values and for storing the collection of values we need data structures. CPP provides built-in libraries of classes for all these data structures and that collection of classes are called STL (Standard Template Libraries ).


STL consists of

  1. ALgorithms
  2. Containers
  3. Iterators
  • Algorithms are the functions used to perform operations on containers
  • For example
sort()
reverse()
count()
find()
binary_search()
lower_bound()
upper_bound()
next_permutation()
prev_permutation()
distance()


  • A container is a holder object that stores a collection of other objects. They are implemented as class templates, which allows great flexibility in the types supported as elements.
  • The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators.
  • Many containers have several functions in common, and share functionalities. The decision of which type of container to use for a specific need does not generally depend only on the functionality offered by the container, but also on the efficiency of some of its members
  • For example :
vector
list
forward_list
deque
priority_queue
stack
set
multiset
map
multimap


  • An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (++) and dereference (*) operators).
  • The most obvious form of iterator is a pointer: A pointer can point to elements in an array and can iterate through them using the increment operator (++). But other kinds of iterators are possible. For example, each container type (such as a list) has a specific iterator type designed to iterate through its elements.
  • For example :


iterator
iterator_traits
reverse_iterator
move_iterator
back_insert_iterator
front_insert_iterator
insert_iterator
istream_iterator
ostream_iterator
input_iterator_tag


Example code with the definition of each container :



 


Get full access to the courses and articles by this instructor
For more info check out our Terms of Use and Privacy Policy.
$5 per hour
Learn with Tanuj shrivastava
You're just a step away from learning 1-on-1 with Tanuj shrivastava. Choose time slots that fit your schedule best and book your consultation.
Your time zone UTC+0 

Learn with the best. Get access to all existing and future courses and articles created by Tanuj shrivastava.

Recommended instructors

Find instructors for your goals & budget.