make_pair (STL Samples)
說明如何使用 make_pair Visual C++ 標準樣板程式庫 (STL) 函式。
template<class first, class second> inline
pair<first,
second> make_pair(
const first& _X,
const second& _Y
)
備註
![]() |
---|
在原型中的類別/參數名稱不相符的標頭檔中的版本。某些已修改以提高可讀性。 |
make_pair STL 函式會建立包含任何型別的兩個資料項目的配對結構。
範例
// 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;
}
Output
18 3.14
10 1
需求
標頭: <utility>