pair in c++
// make_pair example
#include <utility> // std::pair
#include <iostream> // std::cout
int main () {
std::pair <int,int> foo;
std::pair <int,int> bar;
foo = std::make_pair (10,20);
bar = std::make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char>
std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
std::cout << "bar: " << bar.first << ", " << bar.second << '\n';
return 0;
}
//CPP program to illustrate auto-initializing of pair STL
#include <iostream>
#include <utility>
using namespace std;
int main()
{
pair <int, double> PAIR1 ;
pair <string, char> PAIR2 ;
cout << PAIR1.first ; //it is initialised to 0
cout << PAIR1.second ; //it is initialised to 0
cout << " ";
cout << PAIR2.first ; //it prints nothing i.e NULL
cout << PAIR2.second ; //it prints nothing i.e NULL
return 0;
}
//CPP code to illustrate operators in pair
#include <iostream>
#include<utility>
using namespace std;
int main()
{
pair<int, int>pair1 = make_pair(1, 12);
pair<int, int>pair2 = make_pair(9, 12);
cout << (pair1 == pair2) << endl;
cout << (pair1 != pair2) << endl;
cout << (pair1 >= pair2) << endl;
cout << (pair1 <= pair2) << endl;
cout << (pair1 > pair2) << endl;
cout << (pair1 < pair2) << endl;
return 0;
}