The program I am creating will read in data from a text file, which contains a whole bunch of addresses and zip codes.
My question is: every time the file reads in "zip:" (if(text == "zip:")
, the program should print out the tokens that come after it (the specifications ask for token oriented input), meaning the zip code numbers.
Is there a function of some kind that will only print out the zip code and none of the other text that comes after it? Sorry for the long post just want to give as much detail to the program as possible. If there is any other information I should include please let me know. I'm not looking for someone to give me complete program, just some guidance on that specific problem would be much appreciated.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string text;
ifstream inFile;
inFile.open("zips");
while(!inFile.fail()) {
inFile >> text;
if(text == "zip:") {
}
}
inFile.close();
return 0;
}
The input is the file itself being looped through, the user does not enter any input. My desired output is the top ten most frequent zip codes. ex:
Zipz: Frequency:
11204 39
11234 33
22098 27....etc.
Here is a sample of what some of the file contains.
<8975.37428190@62997216886.XmT.srvr@n325.xnot.com> cc: visa addr: 488 Cicada Avenue =4=Z city: Edmonton zip: T5T4M4 $20.00 <833.337428190@2997439800.XmT.srvr@n324.xnot.com> cc: visa addr: 48030 Nevada Blvd =4=Z city: Montecito zip: 95041 $15.00 <8354.37428190@63001226169.XmT.srvr@n326.xnot.com> cc: visa addr: 493 Park Meadow Drive =4=Z city: Alamo zip: 94521 $10.00 <8857.37428190@63001517062.XmT.srvr@n326.xnot.com> cc: mastercard addr: 893 Moraga Avenue =4=Z city: San Bruno zip: 94012 $15.00