How to read integer in Erlang?

后端 未结 5 1324
一生所求
一生所求 2021-01-13 01:57

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.

5条回答
  •  礼貌的吻别
    2021-01-13 02:34

    Try printing the number with ~w instead of ~p:

    1> io:format("~w~n", [[10]]).
    [10]
    ok
    2> io:format("~p~n", [[10]]).
    "\n"
    ok
    

    The ~p format specifier tries to figure out whether the list might be a string, but ~w never guesses; it always prints lists as lists.

提交回复
热议问题