C++ 队列 - 简单示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4592908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ queue - simple example
提问by Ondra
I can't find simple example how to use queues in C++ for pointers to some myclass objects. I have code like this:
我找不到如何在 C++ 中使用队列来指向某些 myclass 对象的简单示例。我有这样的代码:
class myclass{
string s;
};
myclass *p = new myclass();
my_queue.push(p);
//something....
p = my_queue.front();
my_queue.pop();
std::cout << p->s;
What should be declaration of my_queue? Should I use queue or another data structure?
my_queue 的声明应该是什么?我应该使用队列还是其他数据结构?
I need c++ just for small program, thanksfor answers.
我只需要小程序的 C++,谢谢你的回答。
回答by Nim
Simply declare it as below if you want to us the STL queue container.
如果您想使用 STL 队列容器,只需将其声明如下。
std::queue<myclass*> my_queue;
回答by Lightness Races in Orbit
回答by RedX
std::queue<myclass*>
that's it
std::queue<myclass*>
就是这样