7.4.2. Initializing an array in a Declaration with an Initializer List

The elements of an array also can be initialized in the array declaration by following the array name with an equals sign and a brace-delimited comma-separated list of initializers. The program in Fig. 7.4 uses an initializer list to initialize an integer array with five values (line 11) and prints the array in tabular format (lines 13–17).

 1   // Fig. 7.4: fig07_04.cpp 2   // Initializing an array in a declaration. 3   #include <iostream> 4   #include <iomanip> 5   #include <array> 6   using namespace std; 7  8   int main() 9   {10      // use list initializer to initialize array n 11      array< int, 5 > n = { 32, 27, 64, 18, 95 };  12 13 ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.