the std::string class, has it's own search function.
And if you're checking for exact matches you can do;
If string1 == string 2 Then
do stuff
Try using it.
Also don't use EOF to read in files.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
The extraction operator >> does not read past white space (spaces and tabs). So if the name in the file contains a space your program can not work.
you should replace " while (!myfile.eof())" with this:
while( myfile>>number>>name>>DOB>>sex>>residence )
{
}
Reason: eof() does not detect end-of-file until an attempt has been made to read something. That causes the loop to run one too many times. The ifstream object will return 0 (NULL) when it reaches eof, so the loop above will not execute the loop when eof is reached.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343