gpt4 book ai didi

input - Julia :阅读、阅读或其他什么?

转载 作者:行者123 更新时间:2023-12-01 13:46:48 25 4
gpt4 key购买 nike

我想多次要求用户输入整数、浮点数和分数。
我一直在阅读文档,但我对存储用户输入的最佳方式感到困惑。我应该使用 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

最佳答案

通常的方法是使用 readline功能。请注意 STDIN不需要参数,如 readline默认情况下将从 STDIN 读取。

print("Input an integer: ")
n = parse(UInt8, readline())

Input有关从标准输入流获取输入的方法的更多详细信息。

关于input - Julia :阅读、阅读或其他什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35374043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com