I'm neither blaming you, nor CBSE here. You asked for some suggestions, and I gave mine [IMO].
I meant this statement specifically:
PHP Code:
fadd.write((char*)&m1,sizeof(m1));
Don't do it, even though it looks like a very easy method of writing objects to a file directly, it can always go wrong.
Instead, write a
movie::write() method that writes all the values in a line normally, like:
PHP Code:
fadd << id << " " << title << " " << year << " " << etc << endl; // To write one line
Which you can then read by a
movie::readall() method like:
PHP Code:
while (fall) {
fall >> id >> title >> year >> etc; // To read one line.
// Conditions, output, etc.
}
Strings in C++ are very easy to use via the
string class. Here's a tiny demo:
PHP Code:
#include <iostream>
using namespace std;
class Foo {
string a;
public:
void seta (string t) { a = t; } // Sets a
string geta () { return a; } // Returns a
void adda (string t) { a += t; } // Appends a
};
int main () {
Foo t;
string foo("Hello"), bar(" World");
t.seta(foo);
cout << t.geta() << endl;
t.adda(bar);
cout << t.geta() << endl;
return 0;
// Output:
// Hello
// Hello World
}
P.s. You're on the internet, there's no limitation on learning here. You can very well ignore the standards part of my suggestion, or use sites like cplusplus.com and others to know more about it and its standard libraries. And, gets() is standard but its dangerous to use (some bounding flaws exist), instead you could perhaps use cin.getline() or fgets() methods to read a full line, with a bound.
P.p.s. My examples are just that, examples. You can of course write and read in any order or condition you like (even with different delimiters), but make sure its not the way you're doing it right now.