Philipp wrote:
Gernot Frisch wrote:
"Philipp" <no*************@hotmail.com> schrieb im Newsbeitrag
news:41******@epflnews.epfl.ch...
Hello,
How can you copy a stream (or change a reference to it)?
Imagine a function which writes "Hello" to a filestream:
void SomeClass::write(ofstream& originalStream){
ofstream newStream;
newStream = originalStream; // this does not work
newStream << "Hello" << endl;
}
How can I make that right? Thanks for your answers Phil
Why do you want to do this? There's better solutions to your problem,
I think.
Oh I just wanted to change the "name" of the stream so I need not
rewrite some code.
Could you eleborate. What does 'name of the stream' mean.
Is it the stream variables name you want to change.
if yes, then you can create a reference to the original object.
void SomeClass::write(ofstream& originalStream){
ofstream& newStream( originalStream );
newStream << "Hello" << endl;
}
Now the names 'originalStream' and 'newStream' refer to the very
same stream object. But a rewrite would be better.
--
Karl Heinz Buchegger
kb******@gascad.at