Input error with readf()
Paul via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 30 04:49:01 PST 2015
If I run the following example program from the 'Programming in
D' book, the input doesn't 'get stuck' as stated in the book but
instead produces the error message given. Have things changed
since that part of the book was written or is it some other
issue? The version that uses " %s" in the call to readf works as
expected.
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);
writeln("Got it: There are ", studentCount, " students",
" and ", teacherCount, " teachers.");
}
How many students are there? 67
How many teachers are there? 5
std.conv.ConvException@/usr/include/dmd/phobos/std/conv.d(1968):
Unexpected '5' when converting from type LockingTextReader to
type int
...
More information about the Digitalmars-d-learn
mailing list