make_pair (STL Samples)
Znázorňuje použití make_pair standardní šablonu knihovny (STL) funkci jazyka Visual C++.
template<class first, class second> inline
pair<first,
second> make_pair(
const first& _X,
const second& _Y
)
Poznámky
[!POZNÁMKA]
Názvy tříd/parametr v prototyp verze v záhlaví souboru neodpovídají.Některé byly upraveny, aby se zlepšila čitelnost.
make_pair STL funkce vytvoří dvojici struktura, která obsahuje dva datové prvky libovolného typu.
Příklad
// 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;
pair1.first=10;
pair1.second=1.0f;
cout << pair1.first << " " << pair1.second << endl;
}
Výsledek
18 3.14
10 1
Požadavky
Záhlaví: <utility>