Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 C++ 中的队列库,我需要从队列中选择最前面的元素并编辑该元素而不将其从队列中删除。有什么办法可以做到这一点?我需要做这样的事情:
queue<int> myQueue; myQueue.push(1); myQueue.push(2); cout << myQueue.front(); // 2 int a = myQueue.front(); a = 3; cout << myQueue.front(); // 3
显然这不起作用=D。有谁知道该怎么做?
front()返回一个参考,
front()
int &a = queue.front(); a = 3;