【发布时间】:2021-06-02 10:41:05
【问题描述】:
我在编译我用 dlang 编写的代码时遇到一个神秘的错误,它显示
“从 string 类型转换为 int 类型时出现意外的 '\n'”
我在 google 上查了一下,但没有找到解决方案(因为 d 不是一种流行的编程语言)。
这是我写的代码-
import std.stdio;
import std.conv;
void main()
{
string a = readln();
auto b = to!int(a);
}
这是产生的完整错误-
std.conv.ConvException@/usr/include/dmd/phobos/std/conv.d(1947): Unexpected '\n' when converting from type string to type int
----------------
/usr/include/dmd/phobos/std/conv.d:85 pure @safe int std.conv.toImpl!(int, immutable(char)[]).toImpl(immutable(char)[]) [0x562507a98a0f]
/usr/include/dmd/phobos/std/conv.d:223 pure @safe int std.conv.to!(int).to!(immutable(char)[]).to(immutable(char)[]) [0x562507a9760f]
source/app.d:11 _Dmain [0x562507a95d34]
Program exited with code 1
【问题讨论】: