www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Input from console

reply Orgoton <orgoton mindless.com> writes:
This may be an awkward question, but how do we get input from the console? I
mean, like scanf()? It worked for numbers, but for strings I'm haveing trouble.
Feb 25 2007
next sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Orgoton wrote:
 This may be an awkward question, but how do we get input from the console? I
mean, like scanf()? It worked for numbers, but for strings I'm haveing trouble.

Example: --- import std.stdio; import std.cstream; void main(char[][] args) { for (size_t i = 0; i < 5; i++) { char[] line = din.readLine(); writefln("You typed: ", line); } } --- For more Stream and InputStream methods, see http://www.digitalmars.com/d/phobos/std_stream.html
Feb 25 2007
prev sibling next sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Orgoton wrote:

 This may be an awkward question, but how do we get input from the
 console? I mean, like scanf()? It worked for numbers, but for strings
 I'm haveing trouble.

We use "readf", only problem being that it is missing at the moment... You'll have to use something else, like the streams - or even scanf. (std.cstream for the character streams and std.c.stdio for the C I/O) --anders
Feb 25 2007
prev sibling parent Jesse Phillips <Jesse.K.Phillips+Digitalmars gmail.com> writes:
On Sun, 25 Feb 2007 14:43:34 -0500, Orgoton wrote:

 This may be an awkward question, but how do we get input from the
 console? I mean, like scanf()? It worked for numbers, but for strings
 I'm haveing trouble.

Your best bet would probably be the suggested std.cstream. However, just cause I want to I will point you to my readf function. http://files.openomy.com/public/nascent/stdin.d http://files.openomy.com/public/nascent/test.d Please note that I wrote this when I really didn't know much about scanf or any of the other functions, in fact I know little D and C. It doesn't handle all types, but I do continually use it when I want input in D, and it just feels more D like then those C functions.
Feb 25 2007