template type <T> class pair | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

template type <T> class pair

there are something i don’t know in class pair . what is difference between first and second Inside the brackets ? like pair(T first , T second ) and what is benefit for used this class ? and where can i use it ?

12th May 2019, 3:25 AM
Anoud Al-Subaie
1 Answer
+ 10
https://en.cppreference.com/w/cpp/utility/pair/pair Pair can be used to store data in... pairs. For example, you have 100 students and you wish to store their names and student number. You can always store them as parallel arrays, std::string name[100]; std::string num[100]; or you can store them as an array or a vector of pairs. std::pair<std::string, std::string> s_record[100]; Your question pertains more to make_pair though. In a pair, first refers to the first value (left) in the pair, and second refers to the second value (right) in the pair. https://en.cppreference.com/w/cpp/utility/pair/make_pair
12th May 2019, 3:34 AM
Hatsy Rei
Hatsy Rei - avatar