Question

I want to implement my own Input/Output file API. The reason for why I want to that is that on the Low level there will be many file systems (hard disk, HTTP and some more) and I need to provide an common interface for user. The API looks somewhat like this :

class GIO_CORE
{
public:
GIO_CORE(void);
virtual int open(char* path, int openMode) = 0;
virtual int close() = 0;
virtual void write(char* s, int size) = 0;
virtual void read(char* s, int size) = 0;
    //many more
};

So right now I am implementing Hard disk memory, which is the easiest. The way I want to do it is to keep an ifstream and ofstream pointer to the current file which is used. So I want in Open function use my ifstream or ofstream pointer (depending on OpenMode) to point to opened file, and then in write or read function operate on this fstream. Are there any better ideas to do that ?

EDIT: PROBLEM BELOW RESOLVED

Anyway I am getting compilation error when adding ifstream, and ofstream in the header:

class GIO_Persistent_File_System : public GIO_CORE
{
public:
GIO_Persistent_File_System(void);
int open(char*, int);
int close();
void write(char* s, int size);
void read(char* s, int size);
ifstream infile; **this causes compilation error**

And the error is : "missing ; before identifier infile. missing type specifier - int assumed.

How Can I resolve this ?

Was it helpful?

Solution

Don't forget that types defined in the C++ standard library headers are defined in the std namespace:

std::ifstream infile;

OTHER TIPS

#include <fstream>
using namespace std;

will probably fix your problem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top