Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 25, 2007 Input from console | ||||
---|---|---|---|---|
| ||||
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. |
February 25, 2007 Re: Input from console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Orgoton | 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 |
February 25, 2007 Re: Input from console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Orgoton | 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
|
February 26, 2007 Re: Input from console | ||||
---|---|---|---|---|
| ||||
Posted in reply to Orgoton | 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. |
Copyright © 1999-2021 by the D Language Foundation