Problem:
I am trying to implement a buffer with structure queue <pair<int, int*> >
. In the following code, I am trying to push 100 records in the buffer queue. After that, I am trying to pull records from the buffer again one by one:
#include <bits/stdc++.h>
using namespace std;
int main() {
typedef int TWO_INT_ARR[2];
typedef pair<int,int*> data_record;
queue<data_record>* _buffer = new queue<data_record>();
for(int i=0; i<100; ++i) {
TWO_INT_ARR _two_int_arr;
_two_int_arr[0] = i;
_two_int_arr[1] = i;
data_record _data_record;
_data_record.first = i;
_data_record.second = _two_int_arr;
_buffer->push(_data_record);
}
while(! _buffer->empty()) {
data_record front_record = _buffer->front();
cout << front_record.first << "\t"
<< front_record.second[0] << "\t"
<< front_record.second[1] << endl;
_buffer->pop();
}
return 0;
}
Expected output:
0 0 0
1 1 1
2 2 2
: : :
99 99 99
Actual output:
0 99 99
1 99 99
2 99 99
: : :
99 99 99
Could anyone help me find the fault in my code ?