With does this : do

#include <iostream> #include <vector> // Define first_three_multiples() here: std::vector<int> first_three_multiples(int num){ //Function returns first 3 multiples of num std::vector<int> multiples = {num, num*2, num*3}; return multiples; } int main() { for (int element : first_three_multiples(8)) { std::cout << element << "\n"; } }

What does the colon do in the for loop?
for (int element : first_three_multiples(8)) I don’t get what the colon is doing

#include <iostream> #include <vector> // Define first_three_multiples() here: std::vector<int> first_three_multiples(int num){ //Function returns first 3 multiples of num std::vector<int> multiples = {num, num*2, num*3}; return multiples; } int main() { std::cout << first_three_multiples(8); }

like why doesn’t this work? I’m just outputting the vector

for (int element : first_three_multiples(8)) {
    std::cout << element << "\n";
  }

the color is just another way of saying, iterate on this vector.

For the second example, I’m not aware of C++ being able to “simply” output a vector without anything special done. So if you want to output the elements of a vector you gotta write it explicitly or find some special library that let’s you print out vectors (as you would in javascript or python or other modern languages).