0

I'm supposed to make a queue of vectors to solve a part of my assignment.

However, I do not know how to access my vector stored in the queue (for debugging purposes). I cannot just loop through the queue and cout vectors.

How do I print out all elements of vectors that has been stored in queue?

Here is the smaller copy of the code:

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    string start = "cat";
    string end = "hog"
                
    // Initialization of queue for BFS
    queue<vector<string>> chains;

    // Pushing the starting word in queue chains
    vector<string> init;
    init.push_back(start);
    chains.push(init);

    // I cannot cout vectors
    while (!chains.empty()) {
        cout << chains.front() << endl;
        chains.pop();
    }
}

Thanks for your time!

Carla M
  • 1
  • 1
  • 1
    This is correct. In C++ `<<` is not defined for vectors. You must implement your own loop that prints the contents of a vector, one value at a time. Did you try doing that? – Sam Varshavchik Oct 11 '22 at 02:11
  • I do not know how to implement the loop because I don't know how to access the elements of the vector stored in the queue. Note that they're inside a queue. – Carla M Oct 11 '22 at 03:47

0 Answers0