C + + pair type

Source: Internet
Author: User

The pair type is defined in the utility header file, contains two data values, and the members of the pair class are public, and the two members are named First and second respectively. You can access its data members directly in P.first or P.second way, when creating a pair object, You must provide two type names: The pair object contains two data members corresponding to the type name, and these two types do not have to be the same.


Pair<t1, t2> p1; Creates an empty pair object, which is the T1 and T2 types, with value initialization, such as

Pair<string, string> A;

Pair<string, int>b;

Pair<string, vector<int> > C;


Pair<t1, t2> p1 (v1, v2); Create a pair object, the first member is initialized to V1, and the second member is initialized to V2, as

Pair<string, string> D ("Xixi", "haha");


Make_pair (v1, v2); Creates a new pair object with the values of V1 and V2, whose element types are the types V1 and V2, respectively, as

Pair<int, int> test;

Test= Make_pair ();

The effect is equivalent to Pair<int, int> test;



C + + pair type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.