Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

type Node struct {
	ID    int
	X, Y  int
	Color Color
	Nexts []*Node
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		// Initialize map
		m := map[int]map[int]*Node{}
		for x := 1; x <= w; x++ {
			m[x] = map[int]*Node{}
			for y := 1; y <= h; y++ {
				m[x][y] = &Node{ID: x + y*w, X: x, Y: y}
			}
		}
		for x := 1; x <= w; x++ {
			for y := 1; y <= h; y++ {
				nexts := []*Node{}
				if n, ok := m[x-1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y-1]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x+1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y+1]; ok {
					nexts = append(nexts, n)
				}
				m[x][y].Nexts = nexts
			}
		}

		// Set colors
		queue := []*Node{}
		touchedIDs := map[int]struct{}{}
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					n := m[i+1][y]
					n.Color = ColorBlack
					if c == '@' {
						queue = append(queue, n)
						touchedIDs[n.ID] = struct{}{}
					}
				case '#':
					m[i+1][y].Color = ColorRed
				}
			}
		}

		// Search
		visitedIDs := map[int]struct{}{}
		for {
			if len(queue) == 0 {
				break
			}
			n := queue[0]
			queue = queue[1:]
			visitedIDs[n.ID] = struct{}{}
			for _, next := range n.Nexts {
				if next.Color == ColorRed {
					continue
				}
				if _, ok := touchedIDs[next.ID]; !ok {
					queue = append(queue, next)
					touchedIDs[n.ID] = struct{}{}
				}
			}
		}
		fmt.Println(len(visitedIDs))
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;

void rec(int x,int y);
char map[30][30];
bool isVisit[30][30];
int count=0;
//start_pos
int start_x;
int start_y;
int h,w;

int main()
{
    while (cin >> w >> h) 
    {
        count = 0;
        //start pos
        int start_x;
        int start_y;

        for (int i = 0; i < h; i++) 
        {
            for (int j = 0; j < w; j++) 
            {
                cin >> map[j][i];
                if (map[j][i] == '@') 
                {
                    start_x=j;
                    start_y=i;
                }
                //ついでにisVisit初期化
                isVisit[j][i]=false;
            }
        }
        rec(start_x,start_y);
        cout <<count<<endl;
    }

}

void rec(int x,int y)
{
    if ( y<0 || x<0 || h<=y || w<=x) {return;}
    if ( map[x][y] == '#') {return;}
    if (isVisit[x][y]) { return;}
    isVisit[x][y] = true;
    count++;

    rec(x, y-1);
    rec(x+1, y);
    rec(x, y+1);
    rec(x-1, y);

    return;
}

C++: #include <iostream>
#include <string>

using namespace std;

string map[21];
int w,h;
int dx[] = { -1, 1 , 0 , 0 };
int dy[] = { 0 , 0 , -1, 1 };

void check(int x , int y){
	int mx,my;

	//ãº¶EÌSûüÉ²×é
	for(int i=0 ; i<4 ; i++){
		mx = x + dx[i];
		my = y + dy[i];
		//tB[hOÉoÄ¢È¯êÎ²×é(0ÈãE³Èà)
		if(mx>=0 && mx<w && my>=0 && my<h){
			if(map[my][mx]=='.'){//^C¾Á½çhèÂÔµÄÄA
				map[my][mx] = 'f';
				check( mx , my );
			}
		}
	}
}

int main(){
	int sx,sy,count;

	while(1){
		//ÏÌú»
		count = 0;

		//E³ÌüÍ
		cin >> w >> h;
		
		if(w==0 && h==0)break;//0 0ªüÍ³ê½çI¹

		//üÍµ½lðmap[][]Éãü
		for(int y=0 ; y<h ; y++){
			cin >> map[y];
		}

		for(int y=0 ; y<h ; y++){
			for(int x=0 ; x<w ; x++){
				if(map[y][x]=='@'){//@¾Á½çX^[gn_
					sy = y;
					sx = x;
					map[y][x] = 'f';
				}	
			}
		}
		
		check( sx , sy );//X^[gn_Ìx,yÀWðnµÄ²×é

		//^CÌJEg(fÌÂð¦é)
		for(int y=0 ; y<h ; y++){
			for(int x=0 ; x<w ; x++){
				if(map[y][x]=='f')count++;
			}
		}

		//¦ÌoÍ
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;

int G[1010];
int R[110][110];
int D[1010];
int bfs(int src,int num);

int main() {
	int W,H,root;
	char c;


	while (true) {
		for(int i=0;i<100;i++) {
			for(int j=0;j<100;j++) {
				R[i][j] = 0;
			}
		}
		for(int i=0;i<1000;i++) {
			G[i] = 0;
		}
		for(int i=0;i<1000;i++) {
			D[i] = 100;
		}
		cin >> W >> H;
		if((W == 0) && (H == 0)) break;
		for(int i=0;i<W*H;i++) {
			cin >> c;
			if(c == '.') G[i] = 1;
			if(c == '#') G[i] = 0;
			if(c == '@') {
				G[i] = 1;
				root = i;
			}
		}
		for(int i=0;i<W*H;i++) {
			if(G[i] == 1) {
				if(i%W != 0) { //????????????
					if(G[i-1] == 1) {//??????????????? 
						R[i][i-1] = 1;
					}
				}
				if(i%W != W-1) { //????????????
					if(G[i+1] == 1) { //???????????????
						R[i][i+1] = 1;
					}			

				}
				if(i > W-1) { //???????????????
					if(G[i-W] == 1) { //???????????????
						R[i][i-W] = 1;
					}	

				}
				if(i < W*H-W) {//???????????????
					if(G[i+W] == 1){
						R[i][i+W] = 1;
					}	

				}
			}
		}
		cout << bfs(root,W*H) << endl;
	}
	/*
	for(int i=0;i<99;i++) {
		cout << i << " " << G[i] << endl;
	}
	cout << G[98] << endl;
	cout << R[87][98] << endl;
	*/
	
}





int bfs(int src,int num) {
	int cur,dst;
	int count = 1;
	//cerr << "bfs root = " << src << endl;
	queue<int> Q; // ??´??°????????????????????\????????????
	Q.push(src);
	D[src] = 0; // ?????????
	while (!Q.empty()) {
		
		int cur = Q.front(); // ??????????´????????????????
		Q.pop();
// ???????¢??????¨??¨???
		//cerr << cur << " " << D[cur] << endl;
		for (int dst=0;dst<num;dst++) { // ???????????? dst ????????????
			if ((R[cur][dst] == 1) && (D[dst] == 100)) { // cur ?????? dst ??????????????????dst ???????¨??????????
				D[dst] = D[cur]+1; //
				Q.push(dst); // dst ????¨???????????????????
				count++;
			}
		}
	}
	return count;
}

C++: #include <iostream>
#include <algorithm>
#include <deque>
#include <string>
#include <utility>

#define phb push_back
#define ppf pop_front
#define mkp make_pair
#define r first
#define c second
using namespace std;

typedef pair< int, int > Pr;
const int kDir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int R, C, SR, SC;
char M[25][25];

void read();
void solve();

int main() {
  while (cin >> C >> R, R != 0 && C != 0)
    read(), solve();

  return 0;
}

void read() {
  fill(&M[0][0], &M[25][0], '#');
  for (int i = 1; i <= R; ++i)
    for (int j = 1; j <= C; ++j) {
      cin >> M[i][j];
      if (M[i][j] == '@')
        M[i][j] = '.', SR = i, SC = j;
    }
}

void solve() {
  static int vst[25][25], vst_cnt;
  int res = 0;
  deque< Pr > que;

  que.phb(mkp(SR, SC)), vst[SR][SC] = ++vst_cnt;
  while (!que.empty()) {
    Pr cur = que.front(); que.ppf(), ++res;
    for (int di = 0; di < 4; ++di) {
      Pr nxt(cur.r + kDir[di][0], cur.c + kDir[di][1]);
      if (M[nxt.r][nxt.c] == '.' && vst[nxt.r][nxt.c] != vst_cnt)
        que.phb(nxt), vst[nxt.r][nxt.c] = vst_cnt;
    }
  }

  cout << res << "\n";
}