www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - writing

reply spir <denis.spir gmail.com> writes:
Hello,

write and writeln just write; writef and writefln first format: seems clear=
. But the latter do not work properly with D strings, and the former do not=
 work without format. Is there a practical way to just write anything to th=
e terminal (without caring of its type)?

Is there some rationale about this?
Would it be possible to automatically add \0 to D strings passed to write/w=
riteln (can a programmer define a custom func doing this before delegating =
to builtin funcs, or is it necessarily a job for the compiler?)?
And/or what about having writef/writefln use "%s" as default format (when t=
he first arg is not a string)?

Denis
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3

spir.wikidot.com
Oct 14 2010
parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Thu, 14 Oct 2010 09:58:36 +0200, spir wrote:

 Hello,
 
 write and writeln just write; writef and writefln first format: seems
 clear. But the latter do not work properly with D strings, and the
 former do not work without format. Is there a practical way to just
 write anything to the terminal (without caring of its type)?
 
 Is there some rationale about this?
 Would it be possible to automatically add \0 to D strings passed to
 write/writeln (can a programmer define a custom func doing this before
 delegating to builtin funcs, or is it necessarily a job for the
 compiler?)? And/or what about having writef/writefln use "%s" as default
 format (when the first arg is not a string)?
I don't understand what you mean. This works just fine: import std.stdio; void main() { string s = "Hello world!"; writeln(s); } If I'm misunderstanding you, please explain, or perhaps give a code example. -Lars
Oct 14 2010
parent spir <denis.spir gmail.com> writes:
On Thu, 14 Oct 2010 08:05:09 +0000 (UTC)
"Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> wrote:

 On Thu, 14 Oct 2010 09:58:36 +0200, spir wrote:
=20
 Hello,
=20
 write and writeln just write; writef and writefln first format: seems
 clear. But the latter do not work properly with D strings, and the
 former do not work without format. Is there a practical way to just
 write anything to the terminal (without caring of its type)?
=20
 Is there some rationale about this?
 Would it be possible to automatically add \0 to D strings passed to
 write/writeln (can a programmer define a custom func doing this before
 delegating to builtin funcs, or is it necessarily a job for the
 compiler?)? And/or what about having writef/writefln use "%s" as default
 format (when the first arg is not a string)?
=20 =20 I don't understand what you mean. This works just fine: =20 import std.stdio; =20 void main() { string s =3D "Hello world!"; writeln(s); } =20 If I'm misunderstanding you, please explain, or perhaps give a code=20 example. =20 -Lars
Sorry, seems I just mistake the various C & D ways of coping with strings (= too many forms of char arrays and functions that deal with them). I'll just= stick with D funcs. Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Oct 14 2010