我想多次询问用户输入整数,浮点数和有时分数。 我一直在阅读文档,但我很困惑什么是存储用户输入的最佳方式。我应该使用read,readline还是其他什么? 我们考虑整数:
print("Input an integer: ")
n = read(STDIN,UInt8)
println(n) #returns the ASCII number correspondent
#to the first input character
print("Input an integer: ")
n = parse(UInt8,readline(STDIN))
println(n) #returns the input number correctly
#but I wonder if there is a better way to do it
答案 0 :(得分:3)
通常的方法是使用readline
功能。请注意,不需要STDIN
参数,因为readline
默认会从STDIN读取。
print("Input an integer: ")
n = parse(UInt8, readline())
有关从标准输入流获取输入的方法的详细信息,请参阅Input
。