我是一个学习c++的新手,总有一些问题难住我。比如说如下的题目吧,它是一个对于单词统计的的简单程序,可是我看不懂其中的while循环,希望指点
#include <iostream.h>
#include <string.h> // prototype for strcmp()
const int STR_LIM = 50;
int main()
{
char word[STR_LIM];
int count = 0;
cout << "Enter words (to stop, type the word done):/n";
while (cin >> word && strcmp("done", word))
++count;
cout << "You entered a total of " << count << " words./n";
return 0;
}
#include <iostream.h>
#include <string.h> // prototype for strcmp()
const int STR_LIM = 50;
int main()
{
char word[STR_LIM];
int count = 0;
cout << "Enter words (to stop, type the word done):/n";
while (cin >> word && strcmp("done", word))
++count;
cout << "You entered a total of " << count << " words./n";
return 0;
}
本文介绍了一个简单的C++程序,该程序用于统计用户输入的单词数量,并在用户输入done时结束统计。文章重点解释了程序中while循环的工作原理。

1522

被折叠的 条评论
为什么被折叠?



