Reputation: 6921
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.
Upvotes: 3
Views: 315
Reputation: 49852
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.
Upvotes: 1