readf error bug?
Dennis Ritchie via Digitalmars-d
digitalmars-d at puremagic.com
Sat May 9 01:34:40 PDT 2015
On Saturday, 9 May 2015 at 08:30:31 UTC, Dave Akers wrote:
> The following...
>
> import std.stdio;
>
> void main() {
> write("How many students are there? ");
> int studentCount;
> readf("%s", &studentCount);
> write("How many teachers are there? ");
> int teacherCount;
> readf("%s", &teacherCount);
>
> writefln("Got it: there are %d students.", studentCount);
> writefln("And there are %d teachers.", teacherCount);
> }
>
>
> When given the input...
> 10
> 42
>
> will produce the error...
> std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2013):
> Unexpected '4' when converting from type LockingTextReader to
> type int
>
> I understand what is wrong and how to fix it but the produced
> error is
> incorrect.
To '\ n' does not remain in the input stream, it is necessary to
write so:
-----
readf("%s ", &studentCount);
More information about the Digitalmars-d
mailing list