There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult. C.A.R. Hoare

pair

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

0 Comments


Definition

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

Character

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;
	display(p1);
	return 0;
}

						

Output

    					 
					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.

0 Comments



Please login to add comments.