How to simulate Window's "Press any key to continue..."

mipri mipri at minimaltype.com
Fri Nov 22 04:19:40 UTC 2019


On Friday, 22 November 2019 at 04:10:23 UTC, FireController#1847 
wrote:
> I'm an extreme beginner to DLang (just started using it.. oh, 
> an hour ago?), and I already can't figure out a, what I'd 
> consider, fairly simplistic thing.
>
> This is my current code:
>
> module DTestApp1;
>
> import std.stdio;
>
> int main() {
>     write("Press any key to continue...");
>     stdin.read();
>     return 0;
> }
>
> I am using Visual Studio to write it, and no matter what I do I 
> cannot get it to work. I attempted to import std.stream;, but 
> it said that while it could find the file, it cannot be read. 
> Am I using the wrong function?
>
> For those who don't know, what I'm trying to do is pause the 
> program until literally any key is pressed while in the console.

The error doesn't suggest the right replacement, but it still
tells you that the function you want isn't available:

./test.d(6): Error: no property read for type File, did you mean 
std.stdio.File.readf(alias format, Data...)(auto ref Data data) 
if (isSomeString!(typeof(format)))?

std.stdio's documentation is here: 
https://dlang.org/phobos/std_stdio.html

and readln is a function you can use for your purpose.

   stdin.readln();

Or just:

   readln;




More information about the Digitalmars-d-learn mailing list