C++:pair,make_pair,value_type的示例

01 示例

#include <iostream>
#include <string>
#include <map>
#include <utility>        // make_pair,pair

int main(void)
{
    map<int,string> mapTemp;

    // insert a new element
    mapTemp.insert(make_pair(1,"name_01_FirMtd"));
    mapTemp.insert(pair<int,string>(2,"name_01_SedMtd"));
    mapTemp.insert(map<int,string>::value_type(3,"name_01_TrdMtd"));

    // insert a existed element,it is invalid;
    mapTemp.insert(make_pair(1,"name_02_FirMtd"));
    mapTemp.insert(pair<int,string>(2,"name_02_SedMtd"));
    mapTemp.insert(map<int,string>::value_type(3,"name_02_TrdMtd"));

   //
   map<int,string>::iterator itMap;
   for(itMap= mapTemp.begin();itMap != mapTemp.end(); itMap++)
   {
       cout<<itMap->second<<endl;
   }
   return 0;   
}

02 function
A template function that you can use to construct objects of type pair, where the component types are automatically chosen based on the data types that are passed as parameters

Val1:Value that initializes the first element of pair.
Val2:Value that initializes the second element of pair.
Return:The pair object that's constructed: pair<Type1, Type2>(Val1, Val2).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值