multidimensional char arrays : char array « Data Types « C++ Tutorial






#include <iostream>

using namespace std;

int main()
{
    const int ROWS = 3;
    const int COLUMNS = 3;
    char board[ROWS][COLUMNS] = { {'O', 'X', 'O'},
                                  {' ', 'X', 'X'},
                                  {'X', 'O', 'O'} };

    for (int i = 0; i < ROWS; ++i)
    {
        for (int j = 0; j < COLUMNS; ++j)
            cout << board[i][j];
        cout << endl;
    }

    board[1][0] = 'X';

    for (int i = 0; i < ROWS; ++i)
    {
         for (int j = 0; j < COLUMNS; ++j)
             cout << board[i][j];
         cout << endl;
    }
    return 0;
}








2.20.char array
2.20.1.char array buffers
2.20.2.initialized string
2.20.3.Treating character arrays as strings.
2.20.4.Get line with buffer size for char array reading
2.20.5.Use cin.get() to read a string based on char array
2.20.6.Reverse case using array indexing.
2.20.7.Reverse a string in place.
2.20.8.Copying a string using array notation
2.20.9.Copying a string using pointer notation
2.20.10.Initializing char pointers with strings
2.20.11.Using an array of pointers to char
2.20.12.simple string variable
2.20.13.reads multiple lines, terminates on '$' character
2.20.14.reads string with embedded blanks
2.20.15.Read from keyboard and output char array
2.20.16.multidimensional char arrays