On 2007-09-29 23:29,
ba********@yahoo.com wrote:
Hi to every body...:D
I'm a novice C++ programmer & I've a question,
How can I write a class as follow to a file...
Class A
{
public:
// Accessors Methods...
.
.
.
private:
int itsAge;
string itsName;
// char itsName[ 80 ];
};
I know that, I should use ofstream &....
but there is a problem:
"itsName" is a "string or char*" & It can not be written in desired
file...
Actually it is a char array, and nothing else.
Should I write a self writting method for this class to write itself
to a file or what?
Decide on a file-format for writing you class, then implement
std::ostream& operator(std::ostream& o, const A& a);
so that it writes the members of A in the correct format. For more
information search for serialisation, also take a look in the FAQ:
http://www.parashift.com/c++-faq-lite/
--
Erik Wikström