What is STL in C++?
Coding
C++
Share:
Facebook |
Twitter |
Whatsapp |
Linkedin
Visits:
208
STL basically stands for Standard Template
Library, which is a collection of pre-written code frequently used in Data
structures and Algorithms. It was developed in the early 1990s by Meng Lee and
Alexander Stepanov.
It consists of mainly three components known as containers,
algorithms and iterators. Containers are objects that stores and manipulate
data such as list, vector,set, map and stack. Algorithm are functions which
works on the data stored in the containers such as searching, sorting and also
manipulating data. Iterators are object that navigates through the elements of
a container easily.
STL has became an significant part of competitive programming, also
it provides efficient and robust code.
Algorithm
·
Declare a
string and a character you want to remove. Then store them in a variable.
·
Loop through
each character in a string.
·
Check if the
current character matches to the character you want to remove.
·
Repeat the
above two processes until all occurrences of the character are removed.
·
Print the
modified string.
Approach
·
Approach 1:
Using remove() and erase() function.
·
Approach 2:
Using remove_if() and erase() function.
·
Approach 3:
Using find() and erase() function.
There are several approaches to remove all occurrences of a
character in a string using STL.