having problems with creating a file
I can't seem to figure out why I cannot create a file, when I specify a nonexistent file, it fails, but I can reopen files that already exist. Also I am not sure if deleting the filestream is neccessary
Code:
#include <fstream>
class Record{
private:
char* file_name; //the location of the record on the disk
fstream* pfile; //pointer to the file stream
//it is null if the stream is closed
public:
Record();
~Record();
void open_file(char* input_string);
void close_file();
};
Record::Record()
{
pfile=NULL;
}
void Record::open_file(char* input_string)
{
close_file();
file_name = new char[strlen(input_string)+1];
strcpy(file_name, input_string);
pfile = new fstream(file_name, ios::binary | ios::in | ios::out);
if(!*pfile)
throw file_name;
}
void Record::close_file()
{
if(pfile!=NULL)
{
pfile->close();
delete pfile;//Is this neccesary?
pfile=NULL;
}
}
Record::~Record()
{
delete [] file_name;
close_file();
}