您当前的位置: 首页 >  c++
  • 0浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ std::pair<,> 是什么怎么用

软件工程小施同学 发布时间:2021-08-19 14:37:54 ,浏览量:0

std::pair主要的作用是将两个数据组合成一个数据,两个数据可以是同一类型或者不同类型。

例如std::pair 或者 std::pair等。

pair实质上是一个结构体,其主要的两个成员变量是first和second,这两个变量可以直接使用。

#include 
 
#include 
#include 
using namespace std;
 
 
int main () 
{
    pair  product1 ("tomatoes",3.25);
    pair  product2;
    pair  product3;
 
    product2.first = "lightbulbs"; // type of first is string
    product2.second = 0.99; // type of second is double
    product3 = make_pair ("shoes",20.0);
 
    cout             
关注
打赏
1665320866
查看更多评论
0.5526s