Hi I am new to C++. I'm trying to figure out how to make an address book that lets you search the contents by the first name. Here is my program. It displays all the names first and then its suppose to search for the a person info by the users input. I'm very confused!
[code=cpp]
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
ifstream file("a7N.txt") ;
if (file.is_open() )
{
while (! file.eof() )
{
getline (file,line);
cout <<line << endl;
}
system("PAUSE") ;
ifstream file("a7N.txt") ;
char ch, fword;
string line1, num, num2,line4;
;
if(file >>ch>> line1 >> num >> num2 >>line4) {
cout << "[ "
<< ch << ' '
<< line1 << ' '
<< num << ' '
<< num2 << ' '
<< line4<<" ]"
<< endl;
;
}
// read a line using getline
if(getline(file ,line)) {
cout << "[ " << line << " ]" << endl;
cout<<"Please enter a Capital letter?";
cin>>fword;
if (ch == fword)
cout << "[ "
<< ch << ' '
<< line1 << ' '
<< num << ' '
<< num2 << ' '
<< line4<<" ]"
<<endl;
else
cout<< "No Name starts with that letter!"<<endl;
system("PAUSE") ;
return 0;
}
}
}[/code]
[code=cpp]
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
ifstream file("a7N.txt") ;
if (file.is_open() )
{
while (! file.eof() )
{
getline (file,line);
cout <<line << endl;
}
system("PAUSE") ;
ifstream file("a7N.txt") ;
char ch, fword;
string line1, num, num2,line4;
;
if(file >>ch>> line1 >> num >> num2 >>line4) {
cout << "[ "
<< ch << ' '
<< line1 << ' '
<< num << ' '
<< num2 << ' '
<< line4<<" ]"
<< endl;
;
}
// read a line using getline
if(getline(file ,line)) {
cout << "[ " << line << " ]" << endl;
cout<<"Please enter a Capital letter?";
cin>>fword;
if (ch == fword)
cout << "[ "
<< ch << ' '
<< line1 << ' '
<< num << ' '
<< num2 << ' '
<< line4<<" ]"
<<endl;
else
cout<< "No Name starts with that letter!"<<endl;
system("PAUSE") ;
return 0;
}
}
}[/code]
Comment