--- tags: 技巧,書頁 --- # 輸入直到EOF EOF (End of file)為檔案的末端, 通常會出現在需要有持續輸入的題目中 例題: [a004. 文文的求婚](/aidMGHcUTSeFjHzT2JAdfA) ## 解決方法 ### C++ 若`cin`有收到輸入值則可視為`True` 可理解成 ##### 只要有輸入就... ```cpp= while (cin>>input){ // do something } ``` ### Python `EOF`在Python中被視為一種例外, 可以被`EOFError`捕捉 ```python= while True: try: ... except EOFError: break ``` {%hackmd @hlc23/dark-theme %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up