I am writing a class to provide various IO operations that will be used for reading and writing to a file. I am currently trying to inherit from fstream rather then create my own file open, close, etc functions. Currently my sample code below has no functions added, I simply open the write to it and close it. However the test code is unable to successfully open the file when exicuted. I will be adding additional code I can properly inherit from fstream. I get no compiler warnings or errors with this code using g++, and it runs without crashing however I get the "Unable to open file" message, proving the open was not successful.
int main(int argc, char* argv[])
{
FileParser myFileParser;
myFileParser.open("c:\test.txt");
if (myFileParser.is_open())
{
myFileParser << "This is a line.\n";
myFileParser << "This is another line.\n";
myFileParser.close();
}
else
{
cout << "Unable to open file\r\n";
}
myFileParser.close();
return 0;
}
#pragma once
#include <fstream>
using namespace std;
class FileParser: public fstream
{
public:
FileParser(void);
virtual ~FileParser(void);
private:
};
#include "FileParser.h"
FileParser::FileParser(void)
{
}
FileParser::~FileParser(void)
{
}
Any help with this issue would be appreciated.
The issue has now been resolved, thanks for the support.
Regards