您的位置:首页 > 编程语言 > C语言/C++

c++ primer plus 习题5.8(5.9)(while(cin>>word),strcmp())

2015-01-15 20:15 351 查看
#include <iostream>
#include <cstring>     // prototype for strcmp()
const int STR_LIM = 50;
int main()
{
using namespace std;
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>
using namespace std;
int main(){
string word;
int count = 0;

cout << "Enter words (to stop, type the word done):\n";

while (cin >> word &&! (word=="done"))
++count;

cout << "You entered a total of " << count << " words.\n";
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: