1

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 ?

rank1
  • 1,018
  • 4
  • 16
  • 37
  • Why do you provide a concreate file name (char* fileToOpen) instead of using a stream as parameter. You can use several different streams and you don't need to know what kind of source it is (remote file, local file, ...). If your class is getting a concreate file name the implementation needs to handle more than just reading and writing, it needs to know how to open it (several protocols, e.g. http, ftp, ...) and the class gets more complex. Divide and conquer. ;-) – Beachwalker Mar 28 '13 at 12:28

2 Answers2

1

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

std::ifstream infile;
Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • Can You also give me a help on why this causes access violation ? : char* napis = "test"; fstream* o = new fstream(); o = &fstream("nam2.txt"); o->write(napis, 4); o->close(); – rank1 Mar 28 '13 at 13:55
  • @SebastianCygert Actually, that code will give you a compilation error. You should post another question. I know the answer though, so I can answer it as soon as you do. – Joseph Mansfield Mar 28 '13 at 14:02
-2
#include <fstream>
using namespace std;

will probably fix your problem

user1983276
  • 102
  • 5