zoukankan      html  css  js  c++  java
  • #include <utility>

    #include <utility>这个头文件是什么用法

    utility头文件定义了一个pair类型,是标准库的一部分,其原型为:
    template<class _Ty1,
    class _Ty2> struct pair
    { // store a pair of values
    typedef pair<_Ty1, _Ty2> _Myt;
    typedef _Ty1 first_type;
    typedef _Ty2 second_type;

    pair()
    : first(_Ty1()), second(_Ty2())
    { // construct from defaults
    }

    pair(const _Ty1& _Val1, const _Ty2& _Val2)
    : first(_Val1), second(_Val2)
    { // construct from specified values
    }

    template<class _Other1,
    class _Other2>
    pair(const pair<_Other1, _Other2>& _Right)
    : first(_Right.first), second(_Right.second)
    { // construct from compatible pair
    }

    void swap(_Myt& _Right)
    { // exchange contents with _Right
    if (this != &_Right)
    { // different, worth swapping
    std::swap(first, _Right.first);
    std::swap(second, _Right.second);
    }
    }

    _Ty1 first; // the first stored value
    _Ty2 second; // the second stored value
    };
    可以看出这是一个模板类,定义了两个数据成员:first、second和一组成员函数。
    有两个普通构造函数和一个复制构造函数,具体的还定义了一个make_pair函数和一些操作符,
    函数的实现你可以看看标准库的utility头文件。另外,map的元素类型就是pair类型~


    
    

    例子

    #include <iostream>

    #include <utility>

    using namespace std;

    pair<int, int> p;

    int main()

    {

    cin >> p.first >> p.second;

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

    return 0;

    }

    
    
  • 相关阅读:
    XML基础
    vue项目使用WebViewJavascriptBridge
    vue cli3 打包部署 Failed to load resource: net::ERR_FILE_NOT_FO 找不到路径问题
    js 将一个数组插入到另一个数组的方法
    div随意拖动小例子
    带转义符的json解释
    银行卡四位数空隔
    收录-获取时间、日期
    封装的一些例子
    easyui-validatebox 验证
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/7568234.html
Copyright © 2011-2022 走看看