我怎么能存储阵列在C ++排队 [英] how can i store array to queue in c++
本文介绍了我怎么能存储阵列在C ++排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
queue < int* > qq;
for (int i = 0; i < N; i++) {
int cc[2] = {i, i + 1};
qq.push(cc);
}
N为大,但不准确,所以我想用队列。
我想很多存储阵列来排队,但其存储的QQ数组是同一个。
我该怎么办呢?
The N is large but not Exact so I want use queue. I want to store many arrays to queue,but the arrays which qq stored are the same one. How can I do it?
推荐答案
您code将无法工作。每个 CC
在环路同一个堆栈位置。
Your code won't work. Each cc
has the same stack location in the loop.
您需要分配的 CC
数组在堆中,可能使用为int * CC =新的INT [2];
(但你需要删除
它更高版本)。
You need to allocate the cc
array in the heap, perhaps using int *cc = new int[2];
(but then you need to delete
it later).
有一个更好的办法是将有 CC
声明为的std ::矢量
或的std ::阵列
或的std ::元组
(在C ++ 11)。
A better way would be to have cc
declared as a std::vector
or std::array
or std::tuple
(in C++11).
这篇关于我怎么能存储阵列在C ++排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文