Programming is like sex: one mistake and you’re providing support for a lifetime. Michael Sinz
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. |
#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; }
Pass complex number to display function using pair Value from Complex pair: 12, 99
When you need to return 2 values from a function, you can use the pair.
0 Comments