[LC++]Passing ifstream around

Laszlo Boszormenyi boszorme at mazsola.iit.uni-miskolc.hu
Thu Nov 1 00:34:46 UTC 2001


Hi,

I would like to pass ifstream to a dynamicaly created object, but I get
various error messages. Fe. ios::ios is private in the scope of Reader
etc. Can someone help me how to fix this?

Thanks, GCS
-------------- next part --------------
#include <fstream>
#include <iostream>

class Reader {
public:
	Reader(ifstream in);
	~Reader(void);
	int readInt(void);
	short readShort(void);
public:
	ifstream in;
};
-------------- next part --------------
#include <fstream>
#include <iostream>
#include "Reader.h"

Reader::Reader(ifstream in) {
	Reader->in=in;
}
Reader::~Reader() {
}

int Reader::readInt() {
	return -1;
}
short Reader::readShort() {
	return -1;
}
-------------- next part --------------
CC=g++ -Wall

nothing-specified:
	$(CC) -c Reader.cpp -o Reader.o
	$(CC) -c main.cpp -o main.o
	$(CC) Reader.o main.o -o main -lstdc++
-------------- next part --------------
#include <fstream>
#include <iostream>

#include "Reader.h"

int main(int argc, char* argv[]) {
	if(argc!=2) {
		cout << "Please give exactly one filename as argument." << endl;
		exit(1);
	}

	ifstream in(argv[1]);
	Reader* reader=new Reader(in);
	reader->readInt();
	int iType;
	iType=in.get();
	
	if(iType!=0x02) {
		cout << "Not implemented yet, sorry." << endl;
		exit(1);
	}
	int rpfType=iType;
	cout << rpfType << endl;
	cout << "Version one." << endl;
	return 0;
}


More information about the tuxCPProgramming mailing list