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 a

else 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 IF

else if (option=='q') break ;

} //WHILE

return 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 a

else 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

} //WHILE

fin.close;

} //ELSE IF

else if (option=='q') break ;

} //WHILE

return 0;

} //MAIN

 

http://72.14.209.104/search?q=cache:uU96JkcZ4ZsJ:www.cplusplustutor.com/+cplusplustutor.com&hl=en&lr=&strip=1

 

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;

} //WHILE

fin.close();

return 0;

} //MAIN

ebrahimi 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