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 ?
1 Odpowiedź
+ 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