Analyzing Census data:  Town/City/ADP Count

Write a program that reads in a datafile from:


and prints out the number of towns, cities, and 
CDP's.  The user should specify the name of the
file to be analyzed.  This way, if you have data
files from several states saved, you can analyze
all of them with the same program.

Note:  If s is an object of type string that
contains the name of the file you want to open
you can't say:

         ifstream fin(s);

which would seem pretty likely.  Instead, you have
to say:

         ifstream fin(s.begin());

Why and what that means we'll discuss later.  For
now just keep in mind that this is how it works.
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
  // Get input file name
  string filename;
  cout << "Enter file name: ";
  cin >> filename;
  // Open input file
  ifstream fin(filename.c_str());

  if (fin)
    /****** INPUT FILE EXISTS ****************/
    // Initialize town count
    int count_t, count_c, count_cdp;
    count_t = count_c = count_cdp = 0;

    // Read in string until file is finished
    string s;
    while(fin >> s)
      if (s == "town")
      else if (s == "city")
      else if (s == "CDP")
    // Write results
    cout << "There are " << count_t
	 << " towns" << endl;
    cout << "There are " << count_c
	 << " cities" << endl;
    cout << "There are " << count_cdp
	 << " CDP's" << endl;
    /****** INPUT FILE DOES NOT EXIST ********/
    cout << "File not found!" << endl;
  return 0;