digitalmars.D.learn - Input from console
- Orgoton (1/1) Feb 25 2007 This may be an awkward question, but how do we get input from the consol...
- Frits van Bommel (15/16) Feb 25 2007 Example:
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/8) Feb 25 2007 We use "readf", only problem being that it is missing at the moment...
- Jesse Phillips (9/12) Feb 25 2007 Your best bet would probably be the suggested std.cstream. However, just
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
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
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
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