I am trying to compare a string input to a string returned by a function while looping through a file, and if the input is equal to the returned string from the file it should print the details associated with the input string. But it keeps giving me the error message invalid use of void expression
...
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
struct student { /* ... */ };
void search_course(string course)
{
int check = 0;
student st;
ifstream file;
file.open("student.dat", ios::binary | ios::out);
if (!file) {
cout << "No Such file in Database...";
return;
}
while (!file.eof() && check == 0) {
file.read((char *) &st, sizeof(student));
if (strcmp(st.return_prog(), course) == 0) {
st.showid_detail();
}
}
file.close();
}
int main()
{
string course = "physics";
search_course(course);
}
The showid_detail()
is a function in a class which displays information about a record as follows.... id, index, name, course, year, Hall
return_prog()
is a void
function that outputs a course of a student
I expected the code to display all those students doing physics, but it kept telling me invalid use of void expression...