Use of Pair

Source: Internet
Author: User

Just learn to use the pair, if a function has two return worthy words, if the type is the same we can use the structure to return the value, if the type is different can also write their own structure to return the value, but C + + comes with such a return value pair,pair is essentially a structure, But it is much more convenient to use than the structure.

Definition method pair<int,int>p or pair<int, int >p (A, b);

The first is to define the function directly but not to assign a value to the function, and the second is to define the function and directly assign the value of the method, if not at the beginning of the assignment function P=make_pair (A, b);

Pair also stores three variables pair<int, pair<int, int > > Note the last two >> do not write together otherwise the system will be judged to be bit operations, (writing a good fan);

Pair use: Pair has two values, named First,second; When you use it, just call it right.

1#include <iostream>2 using namespacestd;3 intMain ()4 {5pair<int,int>p;6    intA=1, b=3;7p=Make_pair (A, b);8cout<<p.first<<" "<<P.second;9System"Pause");Ten    return 0; One}

The use of the pair is probably the case, I do not have much to understand, especially if you still feel trouble can be a global variable simplified abbreviations such as # # MP Make_pair.

Use of pair

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.