save virtual function output into binary file?

save virtual function output into binary file?

Page 1 of 1

0 Replies - 820 Views - Last Post: 28 November 2009 - 06:29 PM Rate Topic: -----

#1 poplol  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-November 09

save virtual function output into binary file?

Posted 28 November 2009 - 06:29 PM

void Shape::D_square()
{
	for(i=0;i<height;i++)
		{
			for(j=0;j<height;j++)
			{
				cout<<f_char<<" ";
			}
			cout<<"\n";
		}
}

void Shape::D_rectangle()
{
	for(i=0;i<height;i++)
		{
			for(j=0;j<(2*height);j++)
			{
				cout<<f_char<<" ";
			}
			cout<<"\n";
		}
}



for example i have a class and two public member function which is D_square() and D_rectangle()
Is it possible to save those output from function to binary file?

or i need to add extra code like this.....

public:
save(ofstream& out); // saves member data one at a time
load(ifstream& in); // loads member data one at a time
... // other class definition stuff
};

// The save and load methods do things member by member. I do this
// instead of saving the whole object to avoid issues with virtual
// functions.
Shape::save(ofstream& out);
{
out.write(static_cast<char*>&memberVar1, sizeof(memberVar1));
// etc.
}

Shape myObject;
...
myObject.save(ofs);



or i need to save one by one using for loop?

This post has been edited by poplol: 28 November 2009 - 06:49 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1