Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. Alan Kay


Language C++ | Level Intermediate | Category Standard Template Library (STL) | 2015-11-16 21:25:35



The pair is a container for holding two objects as a single object. Pair object can easily pass an argument.


It can be assigned, copied and compared.
Couples together a pair of values, which may be of different types.
The members use to access first and second items and declared as public.
It uses in map and multimap based classes.

source Code

#include "stdafx.h"

#include < utility >
#include < map >
#include < iomanip >
#include < iostream >
using namespace std;

void display(pair < float, float > p)
	cout << "Value from Complex pair: " << p.first << ", " << p.second << '\n';

int _tmain(int argc, _TCHAR* argv[])
	pair < float, float > p1(12, 99);
	cout << "Pass complex number to display function using pair" << endl;
	return 0;



					Pass complex number to display function using pair
					Value from Complex pair: 12, 99

When to use

When you need to return 2 values from a function, you can use the pair.


Please login to add comments.