//
// main.cpp
// Pair
//
// Created by Himanshu on 11/04/22.
//
#include <iostream>
#include <utility>
#include <vector>
#include <string>
using namespace std;
int main () {
//Initializations
//using make_pair
pair<int, int> pairRank = make_pair(1, 98);
//using value init
pair<int, string> pairNameFirst (1, "Anon");
//using copy constructor
pair<int, string> pairTemp(pairNameFirst);
cout<<"pairRank values:"<<endl;
cout<<pairRank.first<<", "<<pairRank.second<<endl;
//accessing pair elements using method get<>
cout<<"pairNameFirst values:"<<endl;
cout<<get<0>(pairNameFirst)<<", "<<get<1>(pairNameFirst)<<endl<<endl;
vector<pair<int, int>> pairRankVector;
vector<pair<int, string>> pairNameVector;
vector<pair<int, int>>::iterator rankItr;
vector<pair<int, string>>::iterator nameItr;
pairRankVector.push_back(pairRank);
pairNameVector.push_back(pairNameFirst);
vector<int> rankMarks = {95, 90, 87, 83, 75};
vector<string> rankNames = {"Bruw", "Cync", "Droke", "Elph", "Frel"};
int n = (int) rankMarks.size();
for (int i=0; i<n; i++) {
pairRankVector.push_back(make_pair(i+2, rankMarks[i]));
pairNameVector.push_back(make_pair(i+2, rankNames[i]));
}
cout<<"Size of pairRankVector: "<<pairRankVector.size()<<endl<<endl;
//accessing vector elements using iterator,
//accessing pair elements using -> operator
//accessing vector element using (*iterator)
for (rankItr = pairRankVector.begin(), nameItr = pairNameVector.begin();
rankItr != pairRankVector.end(); rankItr++, nameItr++) {
cout<<rankItr->first<<" "<<nameItr->second<<" "<<(*rankItr).second<<endl;
}
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBQYWlyCi8vCi8vICBDcmVhdGVkIGJ5IEhpbWFuc2h1IG9uIDExLzA0LzIyLgovLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAppbnQgbWFpbiAoKSB7CiAgICAgCiAgICAvL0luaXRpY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