i compile this code in Microsoft visual studio C++. No errors.. but i cant save the file.. why ??
#include <iostream>
#include <vector>
#include <fstream>
#include <conio.h>
using namespace std;
using std::vector;
class Service {
public:
Service( string d ) { strcpy(servDate,d.c_str()); }
void setDate(string d) { strcpy(servDate,d.c_str()); }
string getDate() { return servDate; }
virtual double GetServiceCharge() { return 0; }
protected:
char servDate[100];
};
class Regular : public Service {
public:
Regular( string d ) : Service(d) {}
double GetServiceCharge() { return 100; }
};
class Special : public Service {
public:
Special( string d ) : Service(d) {}
double GetServiceCharge() { return 200; }
};
void saveFile(vector<Service*> newVecService)
{
int i = 0;
fstream file;
file.open("service.txt",ios::out|ios::trunc|ios::binary);
cout<<"tes";getch();
for(i=0; i < newVecService.size(); i++)
{
if(newVecService[i] != NULL)
{
file.write((char*)&(*newVecService[i]), sizeof(*newVecService[i]));
}
}
file.close();
}
int main() {
Service *newServ;
vector<Service*> vecService(300,newServ);
newServ = new Regular("12/12/2007");
vecService[1] = newServ; // add data to vector
saveFile(vecService);
return 0;
}
thanks in advance..