亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么程序只給數組輸入?cin.get(next)不是還要給next輸入的機會嗎?

為什么程序只給數組輸入?cin.get(next)不是還要給next輸入的機會嗎?

C++
冉冉說 2023-03-03 17:13:40
#include <iostream>using namespace std;const int ArSize = 10;void strcount (const char * str);int main(){char input[ArSize];char next;cout<<"Enter a line: \n"; cin.get(input, ArSize);while (cin) {cin.get(next);while (next != '\n')cin.get(next);strcount (input);cout<<"Enter next line (q): \n";cin.get(input, ArSize);}cout<<"Bye"<<endl;return 0;}void strcount (const char * str){static int total = 0;int count = 0;cout<<"\""<<str<<"\" contains"<<endl;while (*str++)count++;total += count;cout<<count<<" characters " <<endl;cout<<total<<" characters "<<endl;}
查看完整描述

1 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

第一個while是說:

cin函數buffer不為空時(用戶在不斷的輸入)

第二個While:

當next變量的值不是‘\n’(換行符)時,循環執行 cin.get(next);

查看完整回答
反對 回復 2023-03-06
  • 1 回答
  • 0 關注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號