FAQ: Vectors - Review

cout << numbers << endl;

You can’t print the whole vector using cout << (unless you overload the operator).

You could use a range-based loop e.g.

for (const auto& num: numbers) {
    cout << num << endl;
}

or iterate over the indices

for (int i = 0; i < numbers.size(); i++) {
    cout << numbers[i] << endl;
}

Here are a few resources to explore (or you could google to explore the topic in more depth):

2 Likes