Problem With search a file and printing to screen
First time posting
I have a problem with reading a file and printing it to the screen
the .dat file is as follows:
1 will smith 23_jabrone_drive NY
2 john doe 12_mount_ave NY
3 debbie renolds 33_old_farm_rd NY
What I want to do is be able to search the file and print out the information on the screen. The problem is, is that if I press in id 1 it will print out the string. However if I press 2 it will not print the record it will print just the number 2. Can some one please help me?
Here is the code i tried..
int StudentID() // Function : To show people ID
ifstream acctFile ("Accounts1.dat"); // This is the accounts database file
cout<< "Please enter students Private ID Number: "; //This gets retrieves the rec #.
cin >> rec;
acctFile >> rec >> acctRec.firstName
>> acctRec.lastName >> acctRec.address >>acctRec.state;
cout <<" Record Number: " << rec << endl;
cout <<" First Name: " << acctRec.firstName << endl;
cout <<" Last Name: " << acctRec.lastName<< endl;
cout <<" Home Street: " << acctRec.address << endl;
cout <<" State: " << acctRec.state << endl;