This is a question about my homework, but all i need is some guidence. Im writing a program to which i am writing zip codes and there according city to a text file. My problem is that i need to be able to go and search that text file for a zip code and it will show its corrisponding city. Here is the search function that i am trying to use.
void searchZip()
{
string sCity = "";
string sZip = "";
string search = "";
ifstream zipOut ("zipCode.txt"); // Zip code data
if(zipOut.is_open())
{
cout<<"file was opened succesfully";
getline(zipOut,sCity,'#');
cin>>search;
if(zipOut.find(search,0) == true)
{
cout<<"found"<<endl;
}
else {cout<<"Not Found"<<endl;}
}
i really need to know how to manipulate the strings in the txt file to be able to show the zip code to its corrisponding city.
the txt file is formated like this.
93555
ridgecrest
94934
blahhh
49394
blahhh
like so, i was thinking i could search for the zip code then try to use a function to display the next line maybe?? im very lost here. any help is appreciated. thanks