could you explain what while(fin >> q[i].num >> q[i].name >> q[i].type) does exactly?
It reads data from fin to those three variables in order. Then it checks result of operation. As operator>> returns stream it operates on it is equivalent to
1 2
while( fin >> q[i].num >> q[i].name >> q[i].type , //comma operator
fin ) { // std::ios_base::operator bool is called
Opeartor bool returns true if stream in good state (no errors occured and stream is ready for next operation) and returns false if some operation failed (there were nothing to read in file)
So you can read that as "while read is succesfull, do stuff"
In condition expression there is no need for semicolons: it is one logical expression "if a is read from fin1 successfull and (&&) b is read from fin2 succesfully"
and if you use cin wont the loop be infinite?
You can pass invalid data to trigger loop termination or pass EOF signal manually (ctrl+Z on newline on Windows, ctrl+D on Linux)