Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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).

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict