【问题标题】:How to accept input from user (console) in erlang如何在erlang中接受来自用户(控制台)的输入
【发布时间】:2018-10-11 01:21:55
【问题描述】:

我很困惑如何接受来自 Erlang shell 或 Eclipse 控制台的输入? 我想接受来自用户的变量“input”的输入。

p1()->
    io:format(" Codes for business logic of task one \n"),
    spawn(xorgateway, xor_split, []).
xor_split()->
 io:format("enter your decision \n").
   case Value of
         decision1 -> 
            spawn(xorgateway, p2, []);
        decision2 ->
            spawn(xorgateway, p3, []);
        decision3 ->
            spawn(xorgateway, p4, []);
          _->
            io:format("invalid input \n")end.

【问题讨论】:

    标签: erlang


    【解决方案1】:

    我很困惑如何接受来自 Erlang shell 的输入

    -module(my).
    -compile(export_all).
    
        get_data() ->
            {ok, Term} = io:read("Enter a number: "),
            io:format("The number you entered plus one is: ~w~n", 
                      [Term + 1]).
    

    在外壳中:

    8> c(my).        
    my.erl:2: Warning: export_all flag enabled - all functions will be exported
    {ok,my}
    
    9> my:get_data().
    Enter a number: 10.
    The number you entered plus one is: 11
    ok
    
    10> 
    

    请注意,用户需要在输入后输入句点。另见io:getline()io:fread()

    我想接受变量“input”的输入

    input 不是 Erlang 中的变量。 Erlang 变量以大写字母开头。

    【讨论】:

      猜你喜欢
      • 2017-01-06
      • 2012-10-24
      • 2021-07-15
      • 1970-01-01
      • 2021-11-23
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多