make_pair (STL Samples)
发布日期:2022-02-10 13:35:54 浏览次数:40 分类:技术文章

本文共 945 字,大约阅读时间需要 3 分钟。

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

template
inline pair
make_pair( const first& _X, const second& _Y )

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 
#include
using namespace std;/* STL pair data type containing int and float*/typedef struct pair
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;}

18  3.14
10  1
一句话解释:看函数声明我们知道这个make_pair其实是一个类模板,并且返回的是pair类型,make_pair会隐式的类型转换,是pair的智能版本.

参考:

转载地址:https://blog.csdn.net/zoopang/article/details/51152834 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Azure 中国世纪互联是什么?
下一篇:C++如何取得int型的最大最小值

发表评论

最新留言

不错!
[***.144.177.141]2024年03月22日 01时37分19秒