Microsoft KB Archive/156899

= INFO: STL Sample for the make_pair Function =

Article ID: 156899

Article Last Modified on 2/11/2004

-

APPLIES TO

 The Standard C++ Library, when used with:  Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q156899

<div class="notice_section">

NOTE: Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="summary_section">

SUMMARY
The sample code below illustrates how to use the make_pair STL function in Visual C++.

<div class="moreinformation_section">

Prototype
template<class first, class second> inline

pair<first, second> make_pair(const first& _X, const second& _Y) NOTE: The class/parameter names in the prototype may not match the version in the header file. Some have been modified to improve readability.

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

Sample Code
/////////////////////////////////////////////////////////////////////// // Compile options needed: none // // mkpair.cpp: Illustrates how to use the make_pair function. // // Functions: make_pair - creates an object pair containing two data //                       elements of any type. // // Written by Mark Hagen // of Microsoft Technical Support // Copyright (c) 1996 Microsoft Corporation. // All rights reserved. ///////////////////////////////////////////////////////////////////////

/* Compiler options needed: none


 * 1) include
 * 2) include

/* STL pair data type containing int and float

using namespace std;

typedef struct pair<int,float> PAIR_IF;

void main(void)

{ PAIR_IF pair1=make_pair(18,3.14f);

cout << pair1.first << " " << pair1.second << endl; pair1.first=10; pair1.second=1.0f; cout << pair1.first << " " << pair1.second << endl; } Program Output is: <pre class="fixed_text">18 3.14 10 1

<div class="references_section">