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 }

 

相关文章:

  • 2021-09-22
  • 2021-07-11
  • 2022-12-23
  • 2021-12-10
  • 2021-05-20
  • 2021-08-16
  • 2021-12-04
猜你喜欢
  • 2021-08-01
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
相关资源
相似解决方案