Why does toString() exist? It seems useless.

Fawzi Mohamed fmohamed at mac.com
Fri Aug 22 15:18:18 PDT 2008


On 2008-08-22 22:10:21 +0200, Leandro Lucarella <llucax at gmail.com> said:

> Sean Kelly, el 22 de agosto a las 12:46 me escribiste:
>> Leandro Lucarella wrote:
>>> Don, el 18 de agosto a las 12:41 me escribiste:
>>>> I cannot understand the rationale for a toString() member function which
>>>> doesn't support formatting.
>>> I think is useful only for debugging purposes.
>>>> C++ got around this by giving state to the iostream classes.
>>> I think C++ formatting is heavily ill. All the manipulator stuff is
>>> madness.
>> 
>> It's horrific but surprisingly flexible.  I've created stateful formatters for
>> various protocols and made it work all invisibly with the formatting hooks
>> provided in C++.  For example:
>> 
>> std::cout << a << b << c << std::flush;

I think that putting formatting details in the stream is a very good 
idea for serialization, but not for normal textual output, the two 
things are not the same (even if it might be useful to use some xml 
serialization for some objects, and send it together with "normal" 
text).

Fawzi



More information about the Digitalmars-d-learn mailing list