Vectors

6.2 - Vector list initialization


When creating vectors, you can initialize it to a list using curly braces like this:

// Initialize party to "Mario", "Luigi", and "Yoshi".
std::vector<std::string> party{"Mario", "Luigi", "Yoshi"};

// The '=' sign is optional.
// This initialize lucky_numbers to 1, 7, and 8
std::vector<int> lucky_numbers = {1, 7, 8};

Your task is to create and initialize a vector of int called perfect_numbers and initialize it to 6, 28, 496, and 8128 on line number 7.

#include <iostream> #include <vector> int main() { // Create and initialize perfect_numbers after this line! // Prints out each number in perfect_numbers: for (int n : perfect_numbers) { std::cout << n << std::endl; } }