不能两次读取同一个变量
can't readf to the same variable twice
对于这个简单的代码:
long l;
readf("%d", &l);
readf("%d", &l);
当我输入 20 作为第二个数字时,它抛出异常
exception: std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(1995):
从 LockingTextReader 类型转换为 long 类型时出现意外的“2”
为什么会这样,我做错了什么?
在需要使用的第一个换行符之后,缓冲区中仍有一个换行符。
类似于我在这里写的内容:D lang - Using read and readln() in the same program
相同的修复应该有效。
long l;
readf(" %d", &l); // note the leading space
writeln("Got ", l);
readf(" %d", &l); // and again
writeln("Got ", l);
对于这个简单的代码:
long l;
readf("%d", &l);
readf("%d", &l);
当我输入 20 作为第二个数字时,它抛出异常
exception: std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(1995):
从 LockingTextReader 类型转换为 long 类型时出现意外的“2”
为什么会这样,我做错了什么?
在需要使用的第一个换行符之后,缓冲区中仍有一个换行符。
类似于我在这里写的内容:D lang - Using read and readln() in the same program
相同的修复应该有效。
long l;
readf(" %d", &l); // note the leading space
writeln("Got ", l);
readf(" %d", &l); // and again
writeln("Got ", l);