C++ || STL || standard template libraries
C++ STL
1. Pair :
Syntax :
pair <int,char> p1;
it creates a pair {2,'c'} like this.
pair <int,int> p2;
it creates a pair {2,3} like this .
Basic Code :
#include <bits/stdc++.h>
using namespace std;
int main()
{
// cout<<"hello world\n";
pair <int,int> p1 = {1,2};
cout<<p1.first<< " "<< p1.second<<endl;
pair <int, pair<int ,char>> p2 = {1,{2,'c'}};
cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;
pair <int,int> arr[] = {{2,3},{4,5},{6,7}};
cout<<arr[0].first<< " "<<arr[2].second<<" "<<endl;
return 0;
}
using namespace std;
int main()
{
// cout<<"hello world\n";
pair <int,int> p1 = {1,2};
cout<<p1.first<< " "<< p1.second<<endl;
pair <int, pair<int ,char>> p2 = {1,{2,'c'}};
cout<<p2.first<<" "<<p2.second.first<<" "<<p2.second.second<<endl;
pair <int,int> arr[] = {{2,3},{4,5},{6,7}};
cout<<arr[0].first<< " "<<arr[2].second<<" "<<endl;
return 0;
}
Output:
Comments
Post a Comment