Looks like the code is reading data from the data file and storing into the student class (by means of casting the data as a string first).
It looks like it's checking the roll number of the student to see if it matches the argument passed into the function. If it does, it prints the student data. If it doesn't, it prints that the required student doesn't exist.
In this case, the only reason the flag is being used is to print to error message at the end. You could bin it completely by simply closing the file stream and returning right after printing the student data.
flag is a variable, just like any other. Its type is bool. bool variables can take two values: true or false.
The line flag = true; is simply setting the value of the variable to true.
If you look a few lines down, you can see that there is an if statement, that checks the value of flag and outputs some text to stdout if the value is false. If we didn't set the value to true above, it would always output that message, even if the record did exist.