pair练习
/*
编写程序读入一些列string和int型数据,将每一组存储在一个pair对象中,
然后将这些pair对象存储在vector容器里。
*/ #include <iostream>
#include <vector>
#include <utility> //pair在里边定义 using namespace std; int main()
{
vector< pair<string, int> > vp;
string key;
int val;
while(cin >> key >> val)
{
//vp.push_back( make_pair(key, val) );
vp.push_back( pair<string, int>(key, val));
}
for(vector< pair<string, int> >::iterator itor = vp.begin(); itor != vp.end(); ++itor)
{
//cout << (*itor).first << "\t" << (*itor).second << endl; 注意这种方式的括号不能少
cout << itor->first << "\t" << itor->second << endl;
}
system("pause");
return ;
}
pair练习的更多相关文章
- c++ pair 使用
1. 包含头文件: #include <utility> 2. pair 的操作: pair<T1,T2> p; pair<T1,T2> p(v1,v2); pai ...
- 论Pair的重要性
这些天我在用React和D3做图表,从已经实现的图表里复制了一些坐标轴的代码,发现坐标轴上的n个点里,只有第一个点下面能渲染出文字提示,其余点下面都无法渲染出文字. 和组里的FL一起百思不得其解好几天 ...
- 2016 ACM/ICPC Asia Regional Dalian Online 1010 Weak Pair dfs序+分块
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...
- pair的使用
#include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #inc ...
- 【C++】pair
STL的pair,有两个值,可以是不同的类型. template <class T1, class T2> struct pair; 注意,pair在头文件utility中,不要inclu ...
- hackerrank Similar Pair
传送门 Problem Statement You are given a tree where each node is labeled from 1 to n. How many similar ...
- uva12546. LCM Pair Sum
uva12546. LCM Pair Sum One of your friends desperately needs your help. He is working with a secret ...
- C++标准库 -- pair
头文件:<utility> 可访问属性: first 第一个值 second 第二个值 可访问方法: swap(pair) 和另外一个pair交换值 其他相关方法: make_pair(v ...
- 2016 大连网赛---Weak Pair(dfs+树状数组)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5877 Problem Description You are given a rooted ...
- C++学习之Pair
C++学习之Pair Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型, ...
随机推荐
- error/exception/runtime exception区别
(1)java中的异常是什么? 异常指的是程序运行过程中出现的非正常情况或错误,当程序违反了语义规则时,jvm就会将出现的错误表示为一个异常抛出.在java中,一切皆对象,异常也是,它被当作一个对象, ...
- phpexcel错误 You tried to set a sheet active by the out of bounds index: 1解决办法
$objPHPExcel->createSheet($k);
- 解决 MyEclipse build workspace 慢,validation javascript 更慢的问题
自从升级了MyEclipse到7.0,项目Build的时候总是很慢,显示Validating 那些js,html文件.不管我怎么调整 Windows > Preference > MyEc ...
- CentOS 7搭建OpenVPN-Admin
安装注意要点: 1.用户及目录权限 2.openvpn配置文件/etc/openvpn/server.conf,可以设置不同的转发模式等等 3.全程使用apache,不要用其它的如nginx这些,不然 ...
- [原创]互联网公司App测试流程
[原创]互联网公司App测试流程 一款App的发布上线,离不开充分的测试工作,App测试与pc软件测试二者大体流程相同,但也有所区别,其中由于App测试有其固有的特性,所以在测试时流程会有不同,具体我 ...
- hdu4467 Graph
Graph Problem Description P. T. Tigris is a student currently studying graph theory. One day, when h ...
- 在线即时展现 Html、JS、CSS 编辑工具 - JSFiddle
在线即时展现 Html.JS.CSS 编辑工具 - JSFiddle 想对它做些说明介绍.但是它确是那么的easy使用. 兴许有时间,把左側列表作以相关介绍和演示样例演示吧.
- CSDN学院升级公告
CSDN学院将于2015年8月5日凌晨00:00-10:00进行停站升级,升级期间会影响大家的正常訪问和操作.给各位用户带来的不便敬请谅解. 升级结束后有不论什么问题请发邮件到webmaster@cs ...
- delphi services允许跨域访问
delphi services允许跨域访问 unit WebModuleUnit1; procedure TWebModule1.WebModule1DefaultHandlerAction(Send ...
- python测试开发django-14.查询表结果(超详细)
前言 django查询数据库的方法很多,不同的方法返回的结果也不太一样,本篇详细讲解关于查询的13个方法 返回对象是对象列表的: all(), filter(), exclude(), order_b ...