我想模擬這種情況:我的程序剛剛從std :: ifstream(例如,爲「data.txt」文本文件)讀取最後一行並進行一些操作這會花費很多時間,所以有人可能會在文本文件中追加其他行。這裏 while (std::getline(fs, str)) // fs is of std::ifstream type, str is std::string
{
//main co
我做了一個需要完成當進入EOF字符(按Ctrl-Z適用於Windows)和應打印一個簡單的C程序: 通過的情況等級高於或等於5. 如果等級高於或等於8,則通過高通。 對於任何其他情況都失敗。 我使用getchar()作爲用戶輸入(在這種情況下的等級)。 #include <stdio.h>
int main() {
int grade;
puts("Enter a grad
當輸入量未知時,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