Q:

Get array size for use in for loop

I'm trying to get the size of my tiles array so it can be used in the for loop below. However, when compiling, it is showing that .size() is experimental in C++ 2011. What would be the best way to get the size in relation to this loop which checks each tile for the 'E' character? I'm using array instead of a vector so please assist me with arrays. 
void Floor::placePlayer()
{
    bool foundEntry = false;
    int entryX;
    int entryY;

    for (int x = 0; x < tiles.size() && !foundEntry; x++)
    {
        for (int y = 0; y < tiles[x].size() && !foundEntry; y++)
        {
            if (tiles[x][y] == 'E')
            {
                player.set_position (x,y);
                tiles[x][y] = 'P';
            }
        }
    }
}

Also this is my array from the header:
const static int ROWS = 20;
const static int COLS = 30;
char tiles[ROWS][COLS];

Thanks for the help!

A:

In C++ you can use the following function to give you the number of elements in a C-style array:
template<typename T, size_t N>
size_t lengthof( T (&arr)[N] )  { return N; }

Then the loops would be:
for (size_t x = 0; x < lengthof(tiles) && !foundEntry; x++)

    for (size_t y = 0; y < lengthof(tiles[x]) && !foundEntry; y++)

This is safer than hardcoding values because that way, if you later changed the size of your array, your loops would begin to silently access the wrong number of elements.

A:

Why don't you use your const static int used to create the array ?
void Floor::placePlayer()
{
    bool foundEntry = false;
    int entryX;
    int entryY;

    for (int x = 0; x < ROWS && !foundEntry; x++)
    {
        for (int y = 0; y < COLS && !foundEntry; y++)
        {
            if (tiles[x][y] == 'E')
            {
                player.set_position (x,y);
                tiles[x][y] = 'P';
            }
        }
    }
}

