On 11/13/11 15:43, Jayden Shui wrote:
> On Nov 13, 11:49 am, Larry Evans <cppljev...@suddenlink.net> wrote:
>> On 11/13/11 10:33, Larry Evans wrote:
>>
>>
>>
>>
>>
>>
>>
>>> On 11/13/11 10:04, Jayden Shui wrote:
>>>> Hello All,
>>
>>>> I'd like to have an itemized output like
>>
>>>> 1. Topic
>>>> 1.1 Sub Topic
>>>> 1.2 Sub Topic
>>>> 1.2.1 Sub Sub Topic
>>>> 1.2.2 Sub Sub Topic
>>>> 1.3 Sub Topic
>>>> 2. Topic
>> [snip]
>>> That's what:
>>
>>> http://svn.boost.org/svn/boost/sandb...es/boost/iostr...
>>
>>> An example of it's use is found here:
>>
>>> http://svn.boost.org/svn/boost/sandb...es/sandbox/ste...
>>
>> A better example is:
>>
>> http://svn.boost.org/svn/boost/sandb...es/libs/iostre...
>
> I think this should work. But it is too much for me.
Could you explain what you mean by "too much". I guess you
mean you'd want something so complicated. HOwever, since it's
already written, you don't have to deal with complications.
Well, that's not really true when you get a compile error and
have to decipher the error messages; hence, maybe you've got a
point.
> How can I writ a
> new ostream that derived from std:
stream with indent parameter that
> I can manipulate like
>
> class MyOstream : public ostream
> {
> public:
> // Constrictor?
>
> private:
> ostream mOs.
> int mIndent;
> static int const INDENT_INCREMENT = 4;
> }
>
> How to write the constructor for this class?
Before the indent_scoped ostream_buf code, there was a class
called marg_ostream. That worked; however, I had to replace every
call to std::cout with a call to a marg_ostream constructed ffrom
std::cout. Also, I had to define operator<< for each primitive type and
marg_ostream. This was way too much trouble; hence, the
indent_scoped_ostream_buf code was produced. Now, you don't have
to replace every call to std::cout with a call to some new class.
That's because the change is made to the buffer pointer within
std::cout. The reason for the scoped part of the name is that
when the instance of indent_scoped_ostream_buf goes out of scope, the
indent_scoped_ostream_buf destructor restores the original buffer
pointer; hence, no more indentation.
I'd guess that after you've tried something like MyOstream and got it
to work, you'll find the difficulty of using it is more of a burden
than any complexity of indent_scoped_ostream_buf.
HTH.
>
> Thanks a lot!
You're welcome.
Good luck.
-regards,
Larry