|
![](/i/fill.gif) |
Darren New wrote:
> Warp wrote:
>> MyType value = something;
>> std::cout << "The value is: " << value << "\n";
>
> Here's something I've been wondering about that. Say you have your own
> type, and you want a set of flags like hex/oct/decimal or setfill or
> something like that. I.e., you want to be able to say
>
> std::cout << prettyprintindent(4) << myvalue << "\n";
>
> Where does the "4" there get stored? And how can you make it so that
> (say) passing -1 puts back what it was before the previous call for the
> same stream? It would seem that you'd need some sort of data structure
> mapping streams to pretty print indent levels, yes? And no automated way
> of cleaning that up with a destructor?
>
> What am I missing here?
I believe you would create a separate class which inherits from OStream,
and give it a data member to store the 4 in. You would then define the
function prettyprintindent(int) to return your subclass. Since it
inherits, it can still be used like a regular OStream.
...Chambers
Post a reply to this message
|
![](/i/fill.gif) |