我想模擬這種情況:我的程序剛剛從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