bool user_says_yes(){int c;bool initial_response=true;do{if(initial_response)cout<<"(y,n)?"<<flush;else cout<<"Respond with either y or n: "<<flush;do{c=cin.get();}while(c=='\n' || c==' ' || c=='\t');initial_response=false;}while(c!='y' && c!='Y' && c!='n' && c!='N');return (c=='y' || c=='Y');}flush是干嘛用的?\t是干嘛用的?
2 回答

交互式愛情
TA貢獻1712條經(jīng)驗 獲得超3個贊
\t代表Tab字符,就是按鍵盤上的Tab鍵。
flush表示清空鍵盤緩沖區(qū),這個實際上你不用太關(guān)心,就是保證cout把內(nèi)容輸出到屏幕上的意思。
添加回答
舉報
0/150
提交
取消