tags:

views:

38

answers:

1

Hi,

I have a C++ code that has a lot of functions which receives ostream as argument. I now want to string manipulate the content of this ostream. For example, I want to replace all occurrence of certain word with other word.

The actual parameter to these functions is always ofstream. Is there a way to change the creation of this ofstream, such that it will put such manipulating function?

thanks.

+1  A: 

It seems that you should use a random-access container, e.g. std::basic_string, instead of the streams. A stream is not a container, but a one-way data sink or source: Once you've written to it, you cannot access the contents any more. There are exceptions (e.g. string streams), but they provide as streaming interface to a container, unlike file streams.

Philipp