Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

#include <iostream>

using namespace std;


#include <vector>
#include <map>
int main(){
vector<int> v = {10, 20, 30, 40, 50, 60};
v.push_back(70);
v.push_back(80);
v.push_back(90);
v.pop_back();

cout<<v[8]<<endl; // it still returns 90


cout<<v[9]<<endl; // 0 is returned
//Using Iterator
vector<int> ::iterator itr;
for(itr = v.begin(); itr != v.end(); itr++)
cout<<++ *itr; //itr acts like a pointer and IT
ALTERS THE VALUE OF THE VECTOR

//FOR EACH LOOP


for(int x:v)
cout<<x<<endl;

int main()
{
map<int,string> m;
m.insert(pair<int,string>(1,"john"));
m.insert(pair<int,string>(2,"ravi"));
m.insert(pair<int,string>(3,"khan"));
map<int,string>::iterator itr;
for(itr=m.begin();itr!=m.end();itr++)
{
cout<<itr->first<<" "<<itr->second<<endl;
}
map<int,string>::iterator itr1;
itr1=m.find(2);
cout<<"value found is"<<endl;
cout<<itr1->first<<" "<<itr1->second<<endl;
}

You might also like