Initializing an object with a stream in a (!is_eof) while loop

I am writing a program that uses HFST (a finite-state transducer library). I have pre-compiled FST that I'd like to read with HFST and run some strings against it to get output. Basically it works like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() 
{
	HfstInputStream *in = NULL;
	in = new HfstInputStream("pathToFST.hfsto");
	while (not in->is_eof()) 
	{
		if (in->is_bad()) 
		{
			std::cerr << "ERROR: Stream cannot be read." << std::endl;
			exit(1); 
		}
		HfstTransducer t(*in);
		
		//... do stuff with transducer here

	}
	// ... WANT to do stuff with transducer here instead
}


My question related to line 12 ( HfstTransducer t(*in); ). Here I am creating a new HfstTransducer object inside a while loop, so if I want to use it outside the loop, it is not in scope.

Is there another way to initialize it safely, while keeping it in scope of the rest of my program? The reason I ask, is that I want to build a class around this to persist the HfstTransducer object and not have to create a new stream etc. every time I want to use it.

I hope this makes sense, thank you very much.
Topic archived. No new replies allowed.