In software, we rarely have meaningful requirements. Even if we do, the only measure of success that matters is whether our solution solves the customerís shifting idea of what their problem is. Jeff Atwood


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.