#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);
- 1 回答
- 0 關注
- 89 瀏覽
添加回答
舉報
0/150
提交
取消