I think you have to pass ios::trunc flag to the fstream constructor so that the file will be created if it doesn't exist.
data.write(reinterpret_cast<constchar *>(&A),sizeof(ABC));
This will just copy the bytes of A to the file. This works for simple types but will not work when you have pointers and dynamic allocations.
std::string contains at least one pointer internally that points to the characters. Only the pointer will be written to file. The actual character data will not be written to file. When you later try to read the string from the file the internal string pointer will be set but the memory has probably been deallocated already and might be used by other objects and so things will go bad, and possibly result in a crash.
It's better to read and write each class member separately and handle non-POD types like std::string in a way that makes sense for that type.
One way to write a std::string to file is to first write the size of the string to the file, and then write the characters.
well, in actual code i am using many dynamic data structures and some of them can not be fixed due to demand of program. And if i write these for all such cases it'll be too hectic.
I found "Json" somewhere, i need to know if that'll help or not? Any of you have some idea on it?