0% found this document useful (0 votes)
20 views

Program-11: Aim: C++ Program Which Shows The Usage of Standard

The document discusses the Standard Template Library (STL) in C++ and describes some of its key components. It provides examples of using vectors and maps from the STL. Vectors are dynamic arrays that can automatically resize, while maps store elements in a mapped fashion with each element having a unique key-value pair. The code sample demonstrates inserting and searching elements in a vector and map.

Uploaded by

Ajay Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Program-11: Aim: C++ Program Which Shows The Usage of Standard

The document discusses the Standard Template Library (STL) in C++ and describes some of its key components. It provides examples of using vectors and maps from the STL. Vectors are dynamic arrays that can automatically resize, while maps store elements in a mapped fashion with each element having a unique key-value pair. The code sample demonstrates inserting and searching elements in a vector and map.

Uploaded by

Ajay Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM-11

AIM: C++ PROGRAM WHICH SHOWS THE USAGE OF STANDARD


TEMPLATE LIBRARY(MAPS AND VECTORS)
DESCRIPTION:
The Standard Template Library (STL) is a set of C++ template classes to provide common
programming data structures and functions such as lists, stacks, arrays, etc. It is a library of
container classes, algorithms, and iterators. It is a generalized library and so, its components are
parameterized. A working knowledge of template classes is a prerequisite for working with STL.

STL has four components


 Algorithms
 Containers
 Functions
 Iterators
Vectors are same as dynamic arrays with the ability to resize itself automatically when an
element is inserted or deleted, with their storage being handled automatically by the
container.
Maps are associative containers that store elements in a mapped fashion. Each element has a
key value and a mapped value. No two mapped values can have same key values.

CODE:
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<iterator>
using namespace std;

int main() {
vector<int>v(5,0);
for(int t=0;t<5;++t)
cin>>v[t];
v.push_back(5);
v.push_back(6);
cout<<v.size()<<endl;
vector<int>::iterator itr;
21 | 2 k 1 8 / S E / 0 1 4
itr=find(v.begin(),v.end(),5);
if(itr!=v.end())
cout<<itr-v.begin()+1<<endl;
map<int,int>mp;
for(int t=0;t<5;++t)
mp[v[t]]++;
map<int,int>::iterator ptr;
ptr=mp.find(2);
if(ptr!=mp.end())
mp.erase(ptr);
ptr=mp.lower_bound(6);
cout<<ptr->first<<" "<<ptr->second<<endl;
mp.clear();
cout<<mp.size();
return 0;
}

OUTPUT:

22 | 2 k 1 8 / S E / 0 1 4

You might also like