多次元配列の出力の書き方

932 ワード

constexpr size_t rowCnt = 3, colCnt = 4;
int ia[rowCnt][colCnt] = {0};
//-----  for        ----------------------
for (auto &row : ia) {
    for (auto col : row)
        cout << col << ' ';
    cout << endl;
}
//-----       -----------------------------
for (auto p = begin(ia); p != end(ia); ++p) {
    for (auto q = begin(*p); q != end(*p); ++q)
        cout << *q << ' ';
    cout << endl;
}

//-----    ---------------------------------
for (auto p = ia; p != ia + 3; ++p) {
    for (auto q = *p; q != *p + 4; ++q)
        cout << *q << ' ';
    cout << endl;
}
//------        ---------------------------------
using int_array = int[4];
typedef int int_array[4];
for (int_array *p = ia; p != ia + 3; ++p) {
    for (auto *q = *p; q != *p + 4; ++q)
        cout << *q << ' ';
    cout << endl;
}