Recognition of filestream

Hey all, within a class of mine, I construct a class for reading like this

WordStream::WordStream(std::ifstream& fileStream) : inFile(fileStream){
}

Then I also have two methods, next() and
getContext(const WordOccurrence word, size_t numCharsBefore, size_t numCharsAfter).

The problem is that in the getContext() method, the file I opened isn't recognised. So whenever I try a method such as inFile.get(), I get the "not a class, struct, or union" error.

Any clues? it works fine in the next() method.
I don't think you can initialize a stream with another stream, the constructor for ifstream is this:

1
2
ifstream ( );
ifstream ( const char * filename, ios_base::openmode mode = ios_base::in );


I would pass the name of the file rather then a stream (and to me it would be easier anyway).
It sounds like you didn't declare inFile in the first place.
In any case, fstream's copy constructor is private, so you can't do that intialization.
Topic archived. No new replies allowed.