c++要编这么一个程序
我是初学者~
输入一句话~结果是输出这句话有多少个单词~这句话是随机的~
指导一下~
参考答案:#include <iostream>
#include <string>
using namespace std;
int main()
{
string words;
unsigned count = 0;
cout << "Enter a line of words:\n";
while(cin >> words && cin.peek() != '\n')
{
++count;
}
cout << "The line you had inputed has " << count + 1 << " words." << endl;
}