#41248: C++ EOF


ck1090932@gl.ck.tp.edu.tw (陳邦仁)

學校 : 臺北市立建國高級中學
編號 : 131859
來源 : [140.112.24.194]
最後登入時間 :
2025-10-07 15:41:17

此處EOF 不應使用 (!cin.eof())

正確:
int h,m,s;
    while (cin>>h>>m>>s){
        if (h*s<m){
             cout<<h<<" "<<m<<" "<<s<<". I will be late!"<<endl;}
        else{
             cout<<h<<" "<<m<<" "<<s<<". I will make it!"<<endl;}
    }

錯誤:

    while (!cin.eof()){
       int h,m,s;
       cin>>h>>m>>s;
        if (h*s<m){
             cout<<h<<" "<<m<<" "<<s<<". I will be late!"<<endl;}
        else{
             cout<<h<<" "<<m<<" "<<s<<". I will make it!"<<endl;}
    }