1 Replies - 919 Views - Last Post: 27 March 2008 - 07:35 AM Rate Topic: -----

#1 ahen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 06

help please! abstract class & fstream.write()

Posted 27 March 2008 - 06:49 AM

hi all masters.. :P
i have a question about C++ program..

vector<Employee*> vecEmp;
Employee newEmp = new Staff();
vecEmp[Emp::empNo] = newEmp;



and my question is :

how do i save this vector into a text file (.txt or .dat) by using std::fstream?

following my save method give me a run time error
*sigh....

void saveFile(vector<Employee*> newVecEmp)
{
	int i = 0;
	fstream file;

	file.open(EMPLOYEE_FILE,ios::out|ios::trunc|ios::binary);
		
	for(i=0; i < newVecEmp.size(); i++)
	{
		file.write((char*)&newVecEmp[i], sizeof(newVecEmp[i]));
	}
}



a great thanks for you!

Is This A Good Question/Topic? 0
  • +

Replies To: help please! abstract class & fstream.write()

#2 ahen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 06

Re: help please! abstract class & fstream.write()

Posted 27 March 2008 - 07:35 AM

oh ya.. sorry all masters.. the run time error when i calling this read file method:

vector<Employee*> readFile(vector<Employee*> newVecEmp, Employee *newEmp)
{
	int i = 0;
	fstream file;

	file.open(EMPLOYEE_FILE,ios::in|ios::binary);

	if(file.is_open())
	{
		file.read((char*)&newEmp, sizeof(newEmp));
		while(!file.eof())
		{
			newVecEmp[i] = newEmp;
			file.read((char*)&newEmp, sizeof(newEmp));
			++i;
		}
	}
	return newVecEmp;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1