1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
string next, name, street, city, state, zip;
int loc_name, loc_street, loc_city, loc_state, loc_zip, loc_end_contact;
ifstream fin;
fin.open("address.xml");
if (fin.fail())
{
cout << "Input file opening failed.\n";
system("pause");
exit(1);
}
while (!fin.eof())
{
getline(fin, next);
loc_end_contact = next.find("</contact>");
while ((loc_end_contact < 0) || (loc_end_contact >= next.length()))
{
loc_name = next.find("<name>");
loc_street = next.find("<street>");
loc_city = next.find("<city>");
loc_state = next.find("<state>");
loc_zip = next.find("<zip>");
if ((loc_name >= 0) && (loc_name < next.length()))
name = next.substr(10, next.length() - 17);
if ((loc_street >= 0) && (loc_street < next.length()))
street = next.substr(12, next.length() - 21);
if ((loc_city >= 0) && (loc_city < next.length()))
city = next.substr(10, next.length() - 17);
if ((loc_state >= 0) && (loc_state < next.length()))
state = next.substr(11, next.length() - 19);
if ((loc_zip >= 0) && (loc_zip < next.length()))
zip = next.substr(9, next.length() - 15);
getline(fin, next);
loc_end_contact = next.find("</contact>");
}
if (city == "Palmdale")
{
cout << name << endl
<< street << endl
<< city << endl
<< state << endl
<< zip << endl << endl;
}
name.erase(0, name.length());
street.erase(0, street.length());
city.erase(0, city.length());
state.erase(0, state.length());
zip.erase(0, zip.length());
}
fin.close();
return 0;
}
|