分享

tr1中新增加的tuple介绍

 quasiceo 2013-12-10
分类: C++特性 2010-02-13 06:08 447人阅读 评论(0) 收藏 举报

tuple可以最多将10个类型捆绑起来, 用法看代码吧...

 

  1. #include <iostream>  
  2. #include <string>  
  3. #include <tuple>  
  4. #include <stack>   
  5. using namespace std;   
  6.   
  7.   
  8. void Test2()  
  9. {  
  10.     tr1::tuple <charint, string, double> a('A', 1, "TEXT1", 123.321);   
  11.     cout << tr1::get<0>(a) << endl;   
  12.     cout << tr1::get<1>(a) << endl;   
  13.     cout << tr1::get<2>(a) << endl;   
  14.     cout << tr1::get<3>(a) << endl;   
  15.   
  16.     stack <tr1::tuple <string, int> > s;   
  17.     for (int i=0; i<6; i++)  
  18.     {  
  19.         char buf[20];   
  20.         tr1::tuple <string, int> t(string("姓名")+itoa(i, buf, 10), i);   
  21.         s.push(t);   
  22.     }  
  23.     cout << "姓名/t学号" << endl;   
  24.     while (!s.empty())  
  25.     {  
  26.         tr1::tuple <string, int> t(s.top());   
  27.         s.pop();   
  28.         cout << tr1::get<0>(t) << "/t" << tr1::get<1>(t) << endl;   
  29.     }  
  30. }  
  31.   
  32. void main()  
  33. {  
  34.     try  
  35.     {  
  36.         Test2();   
  37.     }  
  38.     catch (exception e)  
  39.     {  
  40.         cout << e.what() << endl;   
  41.     }  
  42. }  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多