1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <array>
using namespace std;
const size_t rows = 2;
const size_t columns = 3;
void printArray( const array< array< int, columns >, rows> & );
int main()
{
array< array< int, columns >, rows > array1 = { 1, 2, 3, 4, 5, 6 };
array< array< int, columns >, rows > array2 = { 1, 2, 3, 4, 5 };
cout << "Values in array1 by row are:" << endl;
printArray( array1 );
cout << "\nValues in array2 by row are:" << endl;
printArray( array2 );
} // end main
// output array with two rows and three columns, using nested for loops, one for rows,
one for columns
void printArray( const array< array< int, columns >, rows> & a )
{
// loop through array's rows
for ( size_t row = 0; row < a.size(); ++row )
{
for ( size_t column = 0; column < a[ row ].size(); ++column )
cout << a[ row ][ column ] << ' ';
cout << endl;
} // end outer for
} // end function printArray
|