Fandy Putra
Fandy Putra

Reputation: 1

Accessing map with pair as the key

As the title said. I'm new to c++. So i wanted to make a map with pair of int as the key and boolean as the value

 map <pair<int,int>,bool>.

how do i assign the value and access it?

Upvotes: 0

Views: 1407

Answers (2)

Dev Pahuja
Dev Pahuja

Reputation: 35

The first argument in

map <pair<int,int>, bool> mp;

is a key of pair. Therefore you can assign a value and access it as -

mp[{1,2}] = true;

Upvotes: 1

MSalters
MSalters

Reputation: 179779

You'll need to pass one std::pair<int,int> object (your comment suggests passing two int objects, but that's no pair yet.)

You can create a std::pair<int,int> like this: std::pair<int,int> {5,7} or figure out the types from the two arguments to std::make_pair(5, 7).

Upvotes: 1

Related Questions