C++Primer Plus第五章结构编程练习8

8.编写一个程序,它使用一个 char 数组和循环来每次读取一个单词,直到用户输入 done 为止。

随后,该程序指出用户输入了多少个单词(不包括done 在内)。下面是该程序的运行情况:
Enter words(to stop,type the word done):
anteater birthday category dumpster
envy finagle geometry done for sure
You entered a total of 7 words.

#pragma region 第五章练习8
/*
## 8.编写一个程序,它使用一个 char 数组和循环来每次读取一个单词,直到用户输入 done 为止。
随后,该程序指出用户输入了多少个单词(不包括done 在内)。下面是该程序的运行情况:
Enter words(to stop,type the word done):
anteater birthday category dumpster
envy finagle geometry done for sure
You entered a total of 7 words.
*/
#if 1
#include<iostream>
#include <cstring>
using namespace std;
int main()
{
	cout << "Enter words (to stop, type the word done): ";
	const char* const	szDone = "done";
	const unsigned	uSize = 64;
	int	cntWord = -1;
	char	word[uSize];
	do {
		cin >> word;
		++cntWord;
	} while (strcmp(szDone, word));
	cout << "You entered a total of  " << cntWord << " words." << endl;
	return 0;
}
#endif 
#pragma endregion

这里使用的是cin接受输入,如果是用getline()函数,本程序会变的复杂,要做隔断和判断

相关推荐

  1. C++Primer Plus结构编程练习8

    2024-05-14 03:40:05       33 阅读
  2. C++ primer plus 编程练习

    2024-05-14 03:40:05       100 阅读
  3. 数据建模和设计练习

    2024-05-14 03:40:05       39 阅读
  4. C++Primer Plus编程练习4

    2024-05-14 03:40:05       28 阅读
  5. 数据结构8:排序(复习)

    2024-05-14 03:40:05       40 阅读
  6. 数据结构——8 排序

    2024-05-14 03:40:05       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-14 03:40:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-14 03:40:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-14 03:40:05       82 阅读
  4. Python语言-面向对象

    2024-05-14 03:40:05       91 阅读

热门阅读

  1. git开发工作流程

    2024-05-14 03:40:05       39 阅读
  2. Rust :给数据类型起一个别名

    2024-05-14 03:40:05       32 阅读
  3. 数据结构(七)复杂度渐进表示

    2024-05-14 03:40:05       28 阅读
  4. 网络接口类型

    2024-05-14 03:40:05       34 阅读
  5. -general textual search application

    2024-05-14 03:40:05       30 阅读
  6. 布隆过滤器的原理简介

    2024-05-14 03:40:05       38 阅读
  7. Go语言中context原理及使用

    2024-05-14 03:40:05       32 阅读
  8. Linux 作业管理 (bg, fg, jobs, kill)

    2024-05-14 03:40:05       28 阅读
  9. Redis的数据完全是存在内存中的吗?

    2024-05-14 03:40:05       33 阅读
  10. vue基础配置

    2024-05-14 03:40:05       33 阅读
  11. picoCTF-Web Exploitation-Web Gauntlet

    2024-05-14 03:40:05       39 阅读
  12. vue3中实现地区下拉选择组件封装

    2024-05-14 03:40:05       29 阅读
  13. PHP数据库

    2024-05-14 03:40:05       24 阅读