11/13/2006
bu4035
Class notes
Today's topic
part b. the name of the file is a variable
Chris' demo search p22
#include
<iostream>#include
<fstream>#include
<string>using
namespace std;main()
{
string EmployeeName, EmployeeSearch, EmployeeEmail;
char
option;while
(1){cout<<"Choose a to APPEND, S to SEARCH, q to QUIT"<<endl;
cin>>option;
if
(option=='a'){cout<<"Enter employee name"<<endl;cin>>EmployeeName;
cout<<"Enter employee email"<<endl;
cin>>EmployeeEmail;
ofstream fout("data1.txt" ,ios::app);
fout<<EmployeeName<<" "<<EmployeeEmail<<endl;fout.close(); }
//OPTION aelse
if (option=='s'){cout<<"Enter Employee Name: ";cin>>EmployeeName;ifstream fin("data1.txt");
while
(fin>>EmployeeName>>EmployeeEmail){if
(EmployeeSearch==EmployeeName){cout<<EmployeeName<<" "<<EmployeeEmail<<endl; }
//IF}
//WHILE}
//ELSE IFelse
if (option=='q') break ;}
//WHILEreturn
0;}
//MAIN
#include
<iostream>#include
<fstream>#include
<string>using
namespace std;main()
{
string EmployeeName, EmployeeSearch, EmployeeEmail;
char
option;while
(1){cout<<"Choose a to APPEND, S to SEARCH, q to QUIT"<<endl;
cin>>option;
if
(option=='a'){cout<<"Enter employee name"<<endl;cin>>EmployeeName;
cout<<"Enter employee email"<<endl;
cin>>EmployeeEmail;
ofstream fout("data1.txt" ,ios::app);
fout<<EmployeeName<<" "<<EmployeeEmail<<endl;fout.close(); }
//OPTION aelse
if ((option=='s')|| (option == 'S')){cout<<"Enter Employee Name: ";cin>>EmployeeSearch;ifstream fin("data1.txt");
while
(fin>>EmployeeName>>EmployeeEmail){if
(EmployeeSearch==EmployeeName){cout<<EmployeeName<<" "<<EmployeeEmail<<endl; }
//IF}
//WHILEfin.close;
}
//ELSE IFelse
if (option=='q') break ;}
//WHILEreturn
0;}
//MAIN


http://www.huntingtonlearning.com/



<td width="288" valign="top"><a href="index.php"><img src="images/logo.gif" alt="Huntington Learning
<td height="32"><img src="images/find.gif" alt="find a center enter your zipcode" width="90"

#include
<iostream>#include
<fstream>#include
<string>using
namespace std;main()
{
char
EmployeeName[20], filename[20], EmployeeEmail[20];char
option;cout<<"Enter Employee Name: ";cin>>filename;
ifstream fin(filename,ios::in);
while
(fin>>EmployeeName>>EmployeeEmail){cout<<EmployeeName<<" "<<EmployeeEmail<<endl;
}
//WHILEfin.close();
return
0;}
//MAINebrahimi text file
email ebrahimia@oldwestbury.edu
email ebrahimidr@gmail.com
office d-222
phone 516-876-8594
strcat(filename, .txt);
Find what chapter this is located