我想模拟这种情况:我的程序刚刚从std :: ifstream(例如,为“data.txt”文本文件)读取最后一行并进行一些操作这会花费很多时间,所以有人可能会在文本文件中追加其他行。这里 while (std::getline(fs, str)) // fs is of std::ifstream type, str is std::string
{
//main co
当输入量未知时,Python 3中读取多行用户输入的最佳方式是什么?多行输入将通过回车 当我尝试使用 while True:
line = input()
if line:
print(line)
else:
break
分离,收到的EOFError 然后,如果我其更改为try-catch块 while True:
line
当我尝试运行它时,我在程序结束时获取了EOF。我真的不知道如何解决它。起初我得到了“如果”作为一个无效的语法,但我认为我能够解决这个问题。感谢您的帮助 而真: try:
print("Do you want to enter a number?")
print("y - yes")
print("n - no")
choice = int(input("E