1 /*
 2     编写程序读入一些列string和int型数据,将每一组存储在一个pair对象中,
 3     然后将这些pair对象存储在vector容器里。
 4 */
 5 
 6 #include <iostream>
 7 #include <vector>
 8 #include <utility>   //pair在里边定义
 9 
10 using namespace std;
11 
12 int main()
13 {
14     vector< pair<string, int> > vp;
15     string key;
16     int val;
17     while(cin >> key >> val)
18     {
19         //vp.push_back( make_pair(key, val) );
20         vp.push_back( pair<string, int>(key, val));
21     }
22     for(vector< pair<string, int> >::iterator itor = vp.begin(); itor != vp.end(); ++itor)
23     {
24         //cout << (*itor).first << "\t" << (*itor).second << endl;   注意这种方式的括号不能少
25         cout << itor->first << "\t" << itor->second << endl;
26     }
27     system("pause");
28     return 0;
29 }

 

posted on 2013-09-10 10:00  可笑痴狂  阅读(405)  评论(0编辑  收藏  举报