Hi there,

I'm trying to use Operator Overloading to save some objects into a text file using the >> operator.

The program is compiling, but instead of saving the objects into the file, it is currently displaying the pointers address to the console.

I've never used Operator Overloading before, so it's a new concept to me.

I'm trying to overload the >> operator for the derived class 'Leads'.

Here is the program:

header file (diary.h) :

Code:
using namespace std;
#include <string>

class Diary
{
public:

	Diary(string mainname, string mainaddress, string  mainpostcode, string maintelno, string maindetails);
	//friend ostream &operator<<(ostream &streamname, Diary obj);

private:

protected:

	string m_Name;
	string m_Address;
	string m_PostCode;
	string m_TelNo;
	string m_Details;

};

Diary::Diary(string mainname, string mainaddress, string  mainpostcode, string maintelno, string maindetails) 
{
	m_Name = mainname;
	m_Address = mainaddress;
	m_PostCode = mainpostcode;
	m_TelNo = maintelno;
	m_Details = maindetails;	
}


//ostream &operator<<(ostream &streamname, Diary obj)
//{
//	streamname << obj.m_Name << " " << obj.m_Address << " " << obj.m_PostCode << " " << obj.m_TelNo << " " << obj.m_Details << endl;
//	return streamname;
//}



//----------------------------------------------------------------
class Leads : public Diary
{
public:

	Leads(string m_Name, string m_Address, string m_PostCode, string m_TelNo, string m_Details, string m_Date, string m_Time);

	friend ostream &operator<<(ostream &streamname, Leads obj);



private:

protected:

	string m_Date;
	string m_Time;

};
Leads::Leads(string mainname, string mainaddress, string mainpostcode, string maintelno, string maindetails, string maindate, string maintime) : Diary(mainname, mainaddress, mainpostcode, maintelno, maindetails) 
{
	m_Date = maindate;
	m_Time = maintime;
}

ostream &operator<<(ostream &streamname, Leads obj)
{
	streamname << obj.m_Name << " " << obj.m_Address << " " << obj.m_PostCode << " " << obj.m_TelNo << " " << obj.m_Details << endl;
	return streamname;
}

main() :

Code:
#include <iostream>
#include <string>
#include <vector>
#include <fstream> 
#include "diary.h"

using namespace std;

int main ()
{
	vector<Diary *>vectorname;

	do{
		int choice = 0;
		cout << "Choose one of the options below:" << endl;
		cout << "1) Enter a lead" << endl;
		cout << "2) Exit the program" << endl;
		cin >> choice;
		cin.ignore();

		switch(choice)
		{
		case 1:
			{
				cout << "You chose to enter a lead" << endl;
				//---------------------
				//Collect the leads details
				//---------------------
				string mainname;
				cout << "Name? " << endl;
				getline (cin, mainname);

				string mainaddress;
				cout << "Address? " << endl;
				getline (cin, mainaddress);

				string mainpostcode;
				cout << "Post Code? " << endl;
				getline (cin, mainpostcode);

				string maintelno;
				cout << "Telephone Number? " << endl;
				getline (cin, maintelno);

				string maindetails;
				cout << "Details? " << endl;
				getline (cin, maindetails);

				string maindate;
				cout << "Date ? DDMMYY " << endl;
				getline (cin, maindate);

				string maintime;
				cout << "Time? 24hr HHMM " << endl;
				getline (cin, maintime);

				cout << "All questions asked" << endl;

				try
				{
					Leads *ptr = new Leads(mainname, mainaddress, mainpostcode, maintelno, maindetails, maindate, maintime);
					vectorname.push_back( ptr );
				}
				catch (bad_alloc& ba)
				{
					cerr << "bad_alloc caught: " << ba.what() << endl;
				}

				cout << "past push Lead to list and before deletion" << endl;
				break;
			}

		case 2:
			{
				cout << "You chose to exit the program" << endl;

				//Save all the objects to the text file:

				ofstream streamname("database.txt"); 
				if(!streamname) { 
					cout << "Cannot open file" << endl; 
					return 1; 
				} 


				for(int a = 0; a < vectorname.size() ; a++)
				{
					//save all objects to the database.txt file

					cout << vectorname[a];
				}

				streamname << "Some text here" << endl; 
				streamname.close();

				//Iterate over the vector to delete all the pointers.
				//Exit the program

				break;
			}
		}
	}
	while(true);

	system ("PAUSE");

	return 0;
}
Thanks for any help with this. It's most appreciated