如何将对整数视为分隔变量?

How to treated pair integer as separated variable?

有什么办法可以分开成对的整数吗? 首先我以某种方式声明队列:

typedef pair<int,int>pr;
queue<pr>que;

我可以轻松地在其中推送单独的变量。例如

    que.push(make_pair(c,p));

现在我从队列中获取值。我必须接受像 myp 这样的任何成对变量。

 pair<int , int> myp = que.front();

现在,有什么方法可以从 myp 中的两个单独的变量中取值,或者直接从队列中的单独变量中取值?

is there any way to take value in two separate variable from myp

是:

auto [c, p] = que.front();

这些被称为结构化绑定,自 C++17 以来一直是该语言的一部分。

is there any way in C++98?

是的。如果查看 std::pair 的文档,您会发现它有两个成员,firstsecond.

int a = myp.first;
int b = myp.second;