What is the correct way in C++ to output a whole container (in this case the targets are vectors and arrays)? Possibly I'd like to put spaces in it, or sort them like this:
1: (first element)
2: (second element)
3: (third element)
and so on...?
What is the correct way in C++ to output a whole container (in this case the targets are vectors and arrays)? Possibly I'd like to put spaces in it, or sort them like this:
1: (first element)
2: (second element)
3: (third element)
and so on...?
The answer is by looping on each element:
// Array
for (int i = 0; i < size_of_array; ++i) {
std::cout << i << ": " << array[i] << "\n";
}
The same for a vector would be the same, but replace i < size_of_array; with i < name_of_vector.size();