How can I copy an entire vector into a queue?
问题 I am looking to copy the entire contents of a vector into a queue in C++. Is this a built in function or is it nessesary to loop over each element? 回答1: If you make a new queue, you can use the constructor: std::vector<int> v = get_vector(); std::queue<long int, std::deque<long int>> q(std::deque<long int>(v.begin(), v.end())); (You can change the underlying container to taste, though deque is probably the best.) If the queue already exists, there's no range-based algorithm, though, you can