Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:38:39+00:00 2026-05-27T21:38:39+00:00

So I’ve been looking at D for about 15 mins, so it’s no wonder

  • 0

So I’ve been looking at D for about 15 mins, so it’s no wonder I have questions, but something strange is happening for me.

I installed D from here and Visual D from here and I’m running everything in Visual Studio 2010 Professional. D examples compile and run and the debugger appears to be working fine.

While going through dsource.org’s fundamental tutorials, I was reading the Wait section when I noticed that if you use writef instead of writefln then the last line of the output prints after the pause.

Here’s the example’s code:

import std.c.stdio; /* for getch() */
import std.process; /* for system() */
import std.stdio; /* for writefln */

void main() { 
    writefln("Press a key (using 'std.c.stdio.getch();' to wait) . . .");
    getch();

    writefln("Waiting again\n(using 'system(\"pause\");'):");
    system("pause");
}

And here’s mine, note the only change is writefln to writef

import std.c.stdio; /* for getch() */
import std.process; /* for system() */
import std.stdio; /* for writefln */

void main() { 
    writef("Press a key (using 'std.c.stdio.getch();' to wait) . . .");
    getch();

    writef("Waiting again\n(using 'system(\"pause\");'):");
    system("pause");
}

With writef the program will display nothing on the screen, pause at getch, then when I press a key I see the prompt:

Press a key (using 'std.c.stdio.getch();' to wait) . . .Waiting again
Press any key to continue . . . 

but NOT “(using ‘system(“pause”);’):”. The parenthetic statement appears after I press a key to get through the ‘pause’ command in the console. If I use writefln it prints, waits, prints both lines, then waits again as you’d expect.

What explains this behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:38:39+00:00Added an answer on May 27, 2026 at 9:38 pm

    Use stdout.flush(); after any calls to write or writef. These latter calls don’t flush the buffer, which is why you’re seeing this behavior. Btw getch is not in std.c.stdio (at least not in D2?), it’s in DMC’s CRT library (SNN.lib), and to properly use it you would have to prototype it as extern (C) int getch();:

    extern (C) int getch();
    import std.process; /* for system() */
    import std.stdio; /* for writefln */
    
    void main() { 
        writef("Press a key (using 'std.c.stdio.getch();' to wait) . . .");
        stdout.flush();
        getch();
    
        writef("Waiting again\n(using 'system(\"pause\");'):");
        stdout.flush();
        system("pause");
    }
    

    But this is not cross-platform compatible due to getch(). If you want to use a nicer user-input facility you can check out Jesse’s cmdln library: https://github.com/he-the-great/JPDLibs/tree/cmdln. It has a rather cool interface:

    auto num = require!(int, "a > 0 && a <= 10")("Enter a number from 1 to 10");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.