/***************************************************
Print town names from census data
***************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// User enters file name
string filename;
cout << "Enter name of input file: ";
cin >> filename;
// Open census data file
ifstream fin(filename);
if (!fin)
{
cout << "Error opening file!" << endl;
return 0;
}
// Read in (and ignore!) header information
string kill;
while( (fin >> kill) && (kill != "Estimates-Base") )
{
// do nothing: ignore header info
}
for(int i=0; i<10; i++)
fin >> kill;
// Loop over each row
while(fin)
{
/***** Process row **************/
// Read name of city/town/village
string t, N;
fin >> t;
if(!fin) break; // failure of (fin >> t) will cause fin to evaluate to false
while(t != "town" && t != "city" && t != "village")
{
N = N + t;
fin >> t;
}
// Print name if town
if (t == "town")
cout << N << endl;
// Read (and ignore) 12 entries
string s;
for(int i=0; i<12; i++)
fin >> s;
}
return 0;
}