就是利用空格计算输入了多少个单词 遇到done的时候停止计算
#include "stdafx.h"
#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Enter words (to stop, type the word done):";
char word[20];
int count = 0;
while (strcmp(word,"done ") != 0)
{
for (int i = 0; word[i] != ' '; i++)
{
cin.get(word[i]);
}
count++;
}
cout << "Your entered a total of " << count << "words.";
system ("pause");
return 0;
}I
#include "stdafx.h"
#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Enter words (to stop, type the word done):";
char word[20];
int count = 0;
while (strcmp(word,"done ") != 0)
{
for (int i = 0; word[i] != ' '; i++)
{
cin.get(word[i]);
}
count++;
}
cout << "Your entered a total of " << count << "words.";
system ("pause");
return 0;
}I
