I was doing this question in data handling that searches through a file for records maintained through structures. I wrote this code, but it is not building:
But guys the code is not giving the correct output; if roll number 3 is on my student.txt, it should display but the program is saying it can't find roll 3.
How did you create the student.txt file. If you read/write binary data you should open the file in binary mode. filein.open("student.txt", ios::binary); // ios::in is not necessary when using std::ifstream.
filein.read((char* ) &s, sizeof(stu));
This will read sizeof(stu) bytes from the file and store them in s as-is. It will not handle text in any special way or care what data types s actually contains. It just copies bytes.
If student.txt is a text file you will have to read it using << (and possibly other functions) the same way you read data from cin.