File Input

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 14 06:55:48 PDT 2017


On 05/13/2017 09:15 PM, JV wrote:
 > it doesn't pause and store but just keeps reading
 >
 >         string studNum;
 >
 >         readf("%s",&studNum);
 >         write(studNum);

That's the normal behavior for reading into strings. If you want to read 
to the end of the line, try this:

import std.stdio;
import std.string;

void main() {
     write("What is your name? ");
     string name = readln.strip;

     writeln("Hello ", name, "!");
}

(It's the same as strip(readln()).)

Here is more information about readln() and strip() as well as 
formattedRead(), which can be more convenient:

   http://ddili.org/ders/d.en/strings.html

Ali



More information about the Digitalmars-d-learn mailing list