作者:小菠萝 | 来源:互联网 | 2023-05-17 02:56
I'm trying to read user input of integer. (like cin >> nInput; in C++)
I found io:fread bif from http://www.erlang.org/doc/man/io.html, so I write code like this.
我正在尝试读取整数的用户输入。 (比如cin >> nInput;在C ++中)我从http://www.erlang.org/doc/man/io.html找到了io:fread bif,所以我写了这样的代码。
{ok, X} = io:fread("input : ", "~d"),
io:format("~p~n", [X]).
{ok,X} = io:fread(“input:”,“〜d”),io:format(“〜p~n”,[X])。
but when I input 10, the erlang terminal keep giving me "\n" not 10. I assume fread automatically read 10 and conert this into string. How can I read integer value directly? Is there any way to do this? Thank you for reading this.
但是当我输入10时,erlang终端一直给我“\ n”而不是10.我假设fread自动读取10并将其变为字符串。我怎样才能直接读取整数值?有没有办法做到这一点?谢谢您阅读此篇。
5 个解决方案