Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

make_pair (STL Samples) 

Illustrates how to use the make_pair Standard Template Library (STL) function in Visual C++.

template<class first, class second> inline
      second> make_pair(
      const first& _X,
      const second& _Y


The class/parameter names in the prototype do not match the version in the header file. Some have been modified to improve readability.

The make_pair STL function creates a pair structure that contains two data elements of any type.

// mkpair.cpp
// compile with: /EHsc
// Illustrates how to use the make_pair function.
// Functions: make_pair - creates an object pair containing two data
//                        elements of any type.

#include <utility>
#include <iostream>

using namespace std;

/* STL pair data type containing int and float

typedef struct pair<int,float> PAIR_IF;

int main(void)
  PAIR_IF pair1=make_pair(18,3.14f);

  cout << pair1.first << "  " << pair1.second << endl;
  cout << pair1.first << "  " << pair1.second << endl;

18  3.14
10  1

Header: <utility>

© 2015 Microsoft