std.stdio.write, writeln, fwrite, fwriteln
Sean Kelly
sean at f4.ca
Thu Dec 28 11:44:23 PST 2006
Lionello Lunesu wrote:
> "Andrei Alexandrescu (See Website For Email)"
> <SeeWebsiteForEmail at erdani.org> wrote in message
> news:45941A78.50908 at erdani.org...
>> Lionello Lunesu wrote:
>>> This is for the cout lovers out there:
>>>
>>> I like writefln, but many times it's doing too much. I often forget to
>>> print
>>> strings explicitly using "%s", to prevent errors in the (rare) case the
>>> string contains %-characters. That's why I've added write, writeln,
>>> fwrite,
>>> fwriteln to std\stdio.d
>> How about the converse read* functions?
>
> I didn't know they existed? Ah wait, they don't! I see, std.stdio is
> actually only std-output : )
Yup, they don't exist, though std.stream does have read functions. As
an alternative, I've put a copy of the readf/unFormat routines I wrote
ages ago online here:
http://www.invisibleduck.org/~sean/code/stdio.d
http://www.invisibleduck.org/~sean/code/unformat.d
http://www.invisibleduck.org/~sean/code/utf.d
They convert everything to dchar internally during processing and this
may not be a terribly optimal decision (though given my limited
understanding of Unicode at the time it seemed the most prudent
approach), but the code may be useful regardless, as it's a complete
implementation of the C99 scanf function with some additions for D. The
utf changes are necessary to preserve the one-char putback guarantee
that C requires, though things admittedly get a bit weird with a single
Unicode char being represented by up to four bytes.
Sean
More information about the Digitalmars-d-announce
mailing list