Equivalent of scanf

torhu no at spam.invalid
Sat Jul 17 15:59:05 PDT 2010


On 18.07.2010 00:41, Michael Koehmstedt wrote:
> I'm having trouble figuring out how to do formatted console input, something
> like C scanf() or C++ templated stream input. Unfortunately, console input
> isn't covered in much detail in TDPL book. There doesn't appear to be much
> discussion about the standard library at all, which was a bit disappointing.
>
> But anyway, what different ways are there to properly do input from the
> console? Fetching a string with readln() is easy enough, but how could I
> fetch, say, an integer value? Conversely, what is the preferred method for
> converting string into integer or floating point values?

The standard library (Phobos) is getting overhauled, which is probably 
why there's not a lot of detail about it in the book.  It's still quite 
limited and buggy.  Up until now, most real D work has probably been 
done using D1 and the Tango library.

There's a scanf implementation in the works, but it's not released yet. 
  You can probably get by with the to() and parse() functions in 
std.conv. C's isdigit() will probably come in handy too, it's defined in 
core.stdc.ctype.


More information about the Digitalmars-d-learn mailing list