Pair in C++ Standard Template Library (STL)


In this tutorial, we will be discussing a program to understand pair in C++ Standard Template Library.

Pair is a container defined in the utility header that contains two values. It is used to combine two values and associate them even if they are of different types.

Example

 Live Demo

#include <iostream>
#include <utility>
using namespace std;
int main(){
   //initializing a pair
   pair <int, char> PAIR1 ;
   PAIR1.first = 100;
   PAIR1.second = 'G' ;
   cout << PAIR1.first << " " ;
   cout << PAIR1.second << endl ;
   return 0;
}

Output

100 G

Updated on: 14-Apr-2020

251 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements