Jef*_*eld 10
处理全行输入很容易.一次处理一个字符有点依赖于系统.如果您使用的是类Unix系统,则可以使用该Unix模块执行此操作:
let get1char () =
let termio = Unix.tcgetattr Unix.stdin in
let () =
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN
{ termio with Unix.c_icanon = false } in
let res = input_char stdin in
Unix.tcsetattr Unix.stdin Unix.TCSADRAIN termio;
res
Run Code Online (Sandbox Code Playgroud)