fork download
  1. //
  2. // main.cpp
  3. // Tuple
  4. //
  5. // Created by Himanshu on 11/04/22.
  6. //
  7.  
  8. #include <iostream>
  9. #include <tuple>
  10. #include <vector>
  11. #include <string>
  12. using namespace std;
  13.  
  14. int main () {
  15.  
  16. //Initializations
  17. //using make_tuple
  18. tuple<int, string, int> tupleFirst = make_tuple(1, "Anon", 98);
  19.  
  20. //using value init
  21. tuple<int, string, int> tupleLast (7, "Glee", 67);
  22.  
  23. //using copy constructor
  24. tuple<int, string, int> tupleTemp(tupleLast);
  25.  
  26.  
  27. cout<<"tupleTemp values:"<<endl;
  28. cout<<get<0>(tupleTemp)<<", "<<get<1>(tupleTemp)<<", "<<get<2>(tupleTemp)<<endl<<endl;
  29.  
  30. vector<int> rankMarks = {95, 90, 87, 83, 75};
  31. vector<string> rankNames = {"Bruw", "Cync", "Droke", "Elph", "Frel"};
  32.  
  33.  
  34. vector<tuple<int, string, int>> nameList;
  35. nameList.push_back(tupleFirst);
  36.  
  37. int n = (int) rankMarks.size();
  38.  
  39. for (int i=0; i<n; i++) {
  40. nameList.push_back(make_tuple(i+2, rankNames[i], rankMarks[i]));
  41. }
  42.  
  43. nameList.push_back(tupleLast);
  44.  
  45. cout<<"Size of (vector) nameList: "<<nameList.size()<<endl<<endl;
  46.  
  47. for (tuple<int, string, int> t: nameList) {
  48. cout<<get<0>(t)<<" "<<get<1>(t)<<" "<<get<2>(t)<<endl;
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
tupleTemp values:
7, Glee, 67

Size of (vector) nameList: 7

1 Anon 98
2 Bruw 95
3 Cync 90
4 Droke 87
5 Elph 83
6 Frel 75
7 Glee 67