(C++) std::pair

January 30, 2018 · View on GitHub

 

 

 

 

 

(C++) std::pair

 

std::pair is a container for holding two values of any data type. So, std::pair can be used instead of a struct with two members.

 


#include <string> #include <utility>   int main() {   //Make a nickname-phonenumber pair   std::pair<std::string,int> p("Bilderbikkel",1234567890); }

 

The function std::make_pair can save typing in creating std::pairs (as it saves you redeclaring the data types).