queue < int* > qq;
for (int i = 0; i < N; i++) {
int cc[2] = {i, i + 1};
qq.push(cc);
}
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?
Your code won’t work. Each
cchas the same stack location in the loop.You need to allocate the
ccarray in the heap, perhaps usingint *cc = new int[2];(but then you need todeleteit later).A better way would be to have
ccdeclared as astd::vectororstd::arrayorstd::tuple(in C++11).