Yes it is possible.
int size=q.size(); for(int i=0;i<size;i++){ std::cout<<"\nCell - "<< q.front(); q.pop(); }
But people in most cases avoid using the for loop, because every time the queue size is checked against the loop counter, where in the middle of n / 2 elements the pop-up iteration will end uncomfortably, since the size will become n / 2, and I will also be n / 2. An example is mentioned below.
for(int i=0;i<q.size();i++){ std::cout<<"\nCell - "<< q.front(); std::cout<<"\tSize: - "<< q.size()<<" I value:"<<i; q.pop(); }
source share