basic interactive readf from stdin
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 26 16:18:17 PST 2015
On 12/26/2015 11:40 AM, Jay Norwood wrote:
> Simple VS console app in D. Reading lines to a string variable
> interactively. Object is to have no extra blank lines in the console
> output. Seems very broken for this use, requiring two extra "enter"
> entries before the outputs both appear. Version DMD32 D Compiler v2.069.2
>
> import std.stdio;
>
> int main(string[] argv)
> {
> string nm;
> stdin.readf("%s\n",&nm);
> writeln("nm:",nm);
> stdin.readf("%s\n",&nm);
> writeln("nm:",nm);
> return 0;
> }
>
> ======== io shown below
> 123
> 456
> nm:123
>
> nm:456
>
Reading lines with readln works in a Linux console:
import std.stdio;
import std.string;
int main(string[] argv)
{
string nm;
nm = readln.strip;
writeln("nm:",nm);
nm = readln.strip;
writeln("nm:",nm);
return 0;
}
Ali
More information about the Digitalmars-d-learn
mailing list