Is there any way to separate paired integer? first i declare queue in a way:
typedef pair<int,int>pr;
queue<pr>que;
i can easily push separate variable in it. e.g.
que.push(make_pair(c,p));
now when i take value from queue. i have to take in any paired variable like myp.
pair<int , int> myp = que.front();
Now, is there any way to take value in two separate variable from myp or directly take value in separate variable from queue?
is there any way to take value in two separate variable from myp
Yes:
auto [c, p] = que.front();
Those are called Structured Bindings and have been part of the language since C++17.
is there any way in C++98?
Yes. If you take a look at the documentation of std::pair, you'll find that it has two members, first, and second.
int a = myp.first;
int b = myp.second;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With