本文主要是介绍【C++ Primer Plus习题】5.9,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:
解答:
#include <iostream>
#include <cstring>
using namespace std;#define SIZE 20int main()
{string words[SIZE];string done = "done";int count = 0;while (true){cout << "请输入单词:" << endl;cin >> words[count++];if (words[count - 1] == done){count--;break;}cin.get();}cout << "在done前一共输入了" << count << "哥单词" << endl;return 0;
}
运行结果:
考查点:
- string的字符串比较
注意:
我走了用了数组保存,不用直接计数也可以.
2024年8月25日20:47:14
这篇关于【C++ Primer Plus习题】5.9的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!