queue 以及 pair 例程

#include <utility>
#include <string>
#include <iostream>

int main()
{
    std::pair<std::string,double> product_1;  //default constructor
    std::pair<std::string,double> product_2("tomatoes",2.30);  //value init
    std::pair<std::string,double> product_3(product_2);   // copy constructor

    product_1=std::make_pair(std::string("lightbulbs"),0.99);  //using make_pair(move)

    product_2.first="shoes"; // the type of first is string
    product_2.second=39.90;  //the type of second is double

    std::cout<<"the price of "<<product_1.first<<"is $"<<product_1.second<<'\n';
    std::cout<<"the price of "<<product_2.first<<"is $"<<product_2.second<<'\n';
    std::cout<<"the price of "<<product_3.first<<"is $"<<product_3.second<<'\n';
}


#include <cstdlib>

#include <iostream>

#include <queue>

using namespace std;

int main()

{

    int e,n,m;

    queue<int> q1;

    for(int i=0;i<10;i++)

       q1.push(i);

    if(q1.empty())

    cout<<"queue is empty.\n";

    n=q1.size();

    cout<<n<<endl;

    m=q1.back();

    cout<<m<<endl;

    for(int j=0;j<n;j++)
    {

       e=q1.front();

       cout<<e<<" ";

       q1.pop();

    }

    cout<<endl;

    if(q1.empty())

    cout<<"queue is empty.\n";

    return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值