Chinaunix首页 | 论坛 | 博客
  • 博客访问: 351783
  • 博文数量: 43
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-29 20:57
文章分类

全部博文(43)

文章存档

2013年(43)

我的朋友

分类: C/C++

2013-06-20 09:45:45

std::pair用法

点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <utility>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main () {
  7.   pair <string,double> product1 ("tomatoes",3.25);
  8.   pair <string,double> product2;
  9.   pair <string,double> product3;
  10.  
  11.   product2.first = "lightbulbs"; // type of first is string
  12.   product2.second = 0.99; // type of second is double
  13.  
  14.   product3 = make_pair ("shoes",20.0);
  15.  
  16.   cout << "The price of " << product1.first << " is $" << product1.second << "\n";
  17.   cout << "The price of " << product2.first << " is $" << product2.second << "\n";
  18.   cout << "The price of " << product3.first << " is $" << product3.second << "\n";
  19.   return 0;
  20. }
转自:http://www.cnblogs.com/lilun/archive/2010/11/01/1865946.html
阅读(2672) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~