当前位置: 首页 > news >正文

pair类型应用举例

在main.cpp里输入程序如下:

#include <iostream>  //使能cin(),cout();

#include <utility>   //使能pair数据类型;

#include <string>    //使能string字符串;

#include <stdlib.h>  //使能exit();

 

//pair类型可以将两个相同的或不同类型的变量,关联在一起;

//在使用pair数据类型前,要应用utility头文件;

using namespace std;

 

unsigned char product_number;

int main()

{

    pair <string,double> product1 ("白菜",3.25);

//声明pair数据类型的对象product1,并且product1.first="白菜",

//product1.second=3.25;

    pair <string,double> product2;  //声明pair数据类型的对象product2;

    pair <string,double> product3;  //声明pair数据类型的对象product3;

    pair <string,string> product4;  //声明pair数据类型的对象product4;

    product2.first = "豆腐";     //为product2.first赋值;

    product2.second = 1.99;      //为product2.second赋值;

    product3 = make_pair ("排骨",20.50);

//使用make_pair()为pair数据类型的对象product3d赋值;

    product4 = make_pair ("购物袋:   1个","备注: 3种以上商品");

//使用make_pair()为pair数据类型的对象product4赋值;

    product_number=0;

    if(product1.first=="白菜")

    {cout << product1.first << ":  " << product1.second << "元/公斤\n";

       product_number++;

    }

    if(product2.first=="豆腐")

    {cout << product2.first << ":  " << product2.second << "元/公斤\n";

       product_number++;

    }

    if(product3.first=="排骨")

    {cout << product3.first << ":  " << product3.second << "元/公斤\n";

       product_number++;

    }

    if(product_number>=3)

    {cout << product4.first << "\n" << product4.second << "\n";

    }

    exit(0); //退出程序;

}

http://www.lryc.cn/news/469223.html

相关文章:

  • 数字 图像处理算法的形式
  • 安徽对口高考Python试题选:输入一个正整数,然后输出该整数的3的幂数相加形式。
  • Node.js是什么? 能做什么?
  • JVM快速入门
  • 理解深度学习模型——高级音频特征表示的分层理解
  • 【HarmonyOS Next】原生沉浸式界面
  • 数据结构 ——— 树的概念及结构
  • 初探Vue前端框架
  • Lucas带你手撕机器学习——岭回归
  • C2W4.LAB.Word_Embedding.Part1
  • hive初体验
  • 云渲染主要是分布式(分机)渲染,如何使用blender云渲染呢?
  • WordPress与WP Engine:关键事件时间线
  • 大数据治理平台建设规划方案(71页WORD)
  • Maven 项目管理工具
  • ubuntu开机启动jar
  • 【目标检测02】非极大值抑制 NMS
  • 104协议调试工具
  • 日常记录:es TransportClient添加证书处理
  • apply call bind 简介
  • 数据结构 单调栈
  • 【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (七):MongoDB的设置
  • 基于flask和neo4j的医疗知识图谱展示问答系统
  • Python——脚本实现datax全量同步mysql到hive
  • Python爬虫教程:从入门到精通
  • pytorh学习笔记——cifar10(四)用VGG训练
  • CRLF、UTF-8这些编辑器右下角的选项的意思
  • 【C++干货篇】——类和对象的魅力(四)
  • 基于java的诊所管理系统源码,SaaS门诊信息系统,二次开发的不二选择
  • O2OA如何实现文件跨服务器的备份