Hello, at the moment I am writing a program which needs to open, close and modify many different files at the same time (typically over 100 at a given time). Because of this requirement of the project, I decided to make a class which contains a vector of pointers to the different fstream instances for the files. That way I have a simple and 'clean' way to handle this many files. The fact that I am using vectors also means I can easily add new fstream instances (open new files) just by using the push_back method etc.
For some reason, I'm having a bit of difficulty getting it to open a new file (it shouldn't be this hard). The program compiles it just doesn't do what I want it to, and I can't work out where the problem is.
using namespace std;
vector<fstream *> m_file;
static CFileManage * hcInstance;
/* Make sure only one instance of this class is generated */
static CFileManage * GetClassInstance();
static void GenerateClassInstance();
/* Make use of the i/o filestream vectors */
bool CreateNewFileInstance(char * filename);
void CreateNewFileInstance(string filename);
void CloseFileInstance(unsigned int vec_idx);
unsigned int GetNumberOfFileInstances();
fstream * GetFileInstance(unsigned int vec_idx);
For some reason, the code compiles, but it doesn't work as expected when it comes to making a new file.
bool CFileManage::CreateNewFileInstance(char * filename)
m_file.push_back( new fstream );
if( m_file.back()->is_open() )
for(idx=0; idx < m_file.size(); idx++)
At a later date I plan to change the CreateFile Methods so that it allows support for binary files aswell as different modes, e.g. app, ate, trunc etc.