Utilizing std::map and std::array for displaying a modulus grid I've written a modulus-type program (using std::vector).  The user inputs a number, and the program displays a modulus grid pertaining to that number.

This is what it looks like (example program output with 12):


(0)  12 24  36  48  60  72  84  96  108  120
(1)  13  25  37  49  61  73  85  97  109  121
(2)  14  26  38  50  62  74  86  98  110  122
(3)  15  27  39  51  63  75  87  99  111  123
(4)  16  28  40  52  64  76  88  100  112  124
(5)  17  29  41  53  65  77  89  101  113  125
(6)  18  30  42  54  66  78  90  102  114  126
(7)  19  31  43  55  67  79  91  103  115  127
(8)  20  32  44  56  68  80  92  104  116  128
(9)  21  33  45  57  69  81  93  105  117  129
(10)  22  34  46  58  70  82  94  106  118  130
(11)  23  35  47  59  71  83  95  107  119  131
(12)  24  36  48  60  72  84  96  108  120  132



Now, I've decided to make it nicer by using std::map and std::array.  I get the same output as before, but with the same alignment issues (fixing those could complicate my display function).

Is this an effective use of these containers (and am I using them correctly)?  If not, what other containers could be used instead?  I'm using std::array instead of std::vector here because I'm keeping the number of columns (array size) at 10.

#include &lt;iostream&gt;
#include &lt;map&gt;
#include &lt;array&gt;

const unsigned NUM_ARR_ELEMS = 10;

std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; getModGrid(unsigned);
void displayModGrid(const std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt;&amp;);

int main()
{
    std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; modGrid;
    unsigned mod;

    std::cout &lt;&lt; "\n\n&gt; Mod: ";
    std::cin &gt;&gt; mod;

    std::cout &lt;&lt; std::endl &lt;&lt; std::endl;
    modGrid = getModGrid(mod);
    displayModGrid(modGrid);

    std::cout &lt;&lt; std::endl &lt;&lt; std::endl;
    std::cin.ignore();
    std::cin.get();
}

std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; getModGrid(unsigned mod)
{
    std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; modRow;
    std::array&lt;unsigned, NUM_ARR_ELEMS&gt; modValues;

    for (unsigned modIter = 0; modIter &lt;= mod; ++modIter)
    {
        for (unsigned arrIter = 0; arrIter &lt; NUM_ARR_ELEMS; ++arrIter)
            modValues[arrIter] = modIter + (mod * (arrIter+1));

        modRow[modIter] = modValues;
    }

    return modRow;
}

void displayModGrid(const std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; &amp;modGrid)
{
    for (auto rowIter = modGrid.cbegin(); rowIter != modGrid.cend(); ++rowIter)
    {
        std::cout &lt;&lt; "  (" &lt;&lt; rowIter-&gt;first &lt;&lt; ")  ";

        for (auto colIter = rowIter-&gt;second.cbegin(); colIter != rowIter-&gt;second.cend(); ++colIter)
        {
            std::cout &lt;&lt; *colIter &lt;&lt; "  ";
        }

        std::cout &lt;&lt; std::endl;
    }
}
main() can be defined lastly, so that the function prototypes can be removed.  This will also allow NUM_ARR_ELEMS to be initialized within main().  The size of either the inner or outer structure can still be accessed via size().
For simple input like this, a command line argument is another option:

int main(int argc, char *argv[])
{
    unsigned int mod;

    // only argument being the file name
    if (argc &lt; 2)
    {
        std::cin &lt;&lt; mod;
    }
    // more than the file name, where only the second is used
    else
    {
        mod = std::atoi(argv[1]);
    }
}


Warning: std::atoi() returns an int, but mod is an unsigned int.  As this is a mismatch (and should be reported by the compiler), something else should be changed.  Either the return value of std::atoi() should be cast to an unsigned int, or mod should just be changed to an int (and adjusted elsewhere).  The latter may be a better option here, and the extra unsigned bit really isn't important.  Input validation (to avoid a negative value) can be done as well.
This type is quite long to copy in different places:


std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt;



so it can become a typedef:

typedef std::map&lt;unsigned, std::array&lt;unsigned, NUM_ARR_ELEMS&gt;&gt; Grid;

Prefer "\n" over std::endl for just a newline.  The latter also flushes the buffer.