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

来源:互联网 发布:淘宝复制天猫宝贝违规 编辑:程序博客网 时间:2024/05/29 17:10
#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; }

0 0
原创粉丝点击