You have a number of problems, I'll deal with them first rather that work with annoying code.
This may be source of your error, but you need to understand (and probably explain) it.
A file can be written as "text" where you get a bunch of characters separated by lines. Or you can pack them into bytes in the file, we call this a binary file and such a file cannot be viewed in a text editor (see that word text again?).
File operations in text mode open a stream and call << operators
File operations in binary mode open the file in binary mode (on Windows) and call read/write.
You can't mix them. From your code, you're writing binary files. Don't do that. Write text files. That way you can look at the files and see if they're correct.
That read/write Student business. What is Student? If it has objects, you're in trouble.
Why are you using char arrays for strings when there's a string class?
Code like:
1 2
|
std::fstream file;
file.open("student.dat",std::ios::out|std::ios::app);
| |
should be:
|
std::ofstream file("student.dat", std::ios::app);
| |
And don't call close on a stream, let the destructor close it for you, that's why it's there.
A word of warning, never use C casts in C++. And when you cast in C++, think really hard if what you're doing is alright; you're overriding the type system and taking full responsibility for the consequences, if you get it wrong you'll crash your program.