我以为我做对了,但它似乎不起作用。我基本上是在试验一个队列,它适用于一种数据类型,但现在我正在尝试添加多个(最后我想要一个 int 和一个 int 列表)。
这是代码:
#include <iostream>
#include <queue>
using namespace std;
int main()
{
struct product {
int x;
int y;
} ;
queue<product> q;
q.push(100, 100);
q.push(200, 100);
q.push(300, 100);
q.push(400, 100);
cout << "Size of the queue: " << q.size() << endl;
while (!q.empty()) {
cout << q.front() << endl;
q.pop();
}
}
它在没有结构的情况下工作,但显然它只接受队列中每个项目的一个变量。有没有办法拥有多个项目?