is pair in stl a container

pair<int,int>p;
how many pairs can p hold.

Only One.
It’s the return type of std::make_pair()

It can hold only one pair. Take it’s function equivalent to a structure/class defined as :


class PAIR {
    .... something
    public:
     //"TYPE GIVEN BY YOU" which is int in this case
    int first,second; 
    ..... other things
};


And what you now are doing is
PAIR p; // assuming the struct as defined above

Thus you have only one pair.

For future , answers for such questions can be easily googled like this.

Since you are new to STL and are experimenting with it this site would solve all your queries :slight_smile:

2 Likes

Yes it is a STL container.

It has two data members : first and second.

It’s structure looks like this :

struct pair{

type1 first;

type2 second;

}

pair < type1, type2 > mypair

1 Like
//