writef
Jason House
jason.james.house at gmail.com
Sun Jan 11 04:08:23 PST 2009
Claus D. Volko wrote:
> Hi,
>
> I'm currently writing a D tutorial for people new to programming, and I've
> experienced some strange behavior:
>
> The following program works as intended:
>
> // The "Hello World!" program
>
> import std.stdio;
> import std.c.stdio;
>
> void main ()
> {
> int i; // Variable definition
> i = 200; // Assignment
> writefln ("Hello World!"); // Function call
> writefln ("The value of i is ", i, "."); // Function call
> getch (); // Function call
> }
>
> But if I replace
>
> writefln ("The value of i is ", i, ".");
>
> with
>
> writef ("The value of i is ", i, ".");
>
> the output of "The value of i is 200." happens only after the keypress.
> Unfortunately, I haven't been able to find any documents about writef on
> the Net which could have explained why it's like this, or whether it's a
> bug. Therefore I'm posting my question to this newsgroup: Why?
I'm going to guess the answer is flushing. I suspect writefln will flush the output following the implied newline, but writef won't. This is similar to most console output libraries I use. For example, C++ uses std::endl for a flushed newline and "\n" for just a newline without flushing.
More information about the Digitalmars-d
mailing list