按照书上的一个例子读取输入的数的次数出现问题
#include<iostream> using namespace std; int main() { int cur = 0, val = 0; if (cin >> cur){ int cnt = 1; while (cin >> val){ if (val == cur) ++cnt; else { cout << cur << " occurs " << cnt << " times" << endl; cur = val; cnt = 1; } } cout << cur << " occurs " << cnt << " times" << endl; } return 0; }
最后一个数是多少次输不出来