I'm fairly new to c++, and I've just finished writing this function but it won't work. I'm trying to copy the text file records into an array then display the record with matching index to the ID the user entered. could you please point out what i've done wrong here. Thanks.
void searchById()
{
int empID[10] = {0};
string firstName[10] = {""};
string lastName[10] = {""};
int month[10] = {0};
int day[10] = {0};
int requestedId = 0;
int index = 0;
//declare object file
ifstream empIn;
empIn.open("employees.txt", ios::in);
cout << endl;
cout << "Enter employee ID to search for, or (-1) to exit: ";
cin >> requestedId;
while (isalnum(empIn.peek()) && index < 10 && requestedId != -1)
{
empIn >> empID[index];
//empIn.ignore(5, '\n');
empIn >> lastName[index];
empIn >> firstName[index];
empIn >> month[index];
empIn.ignore();
empIn >> day[index];
index++;
}//end while
The user should enter an employee ID, the function then should search in text file records for matching ID and display the entire record.
The function actually is not showing anything, and I can't figure why.