栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++Primer第五版 练习6.17

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++Primer第五版 练习6.17

题目描述:

代码详解(对题目的解释详见相应代码的注释) :

#include
using namespace std;
#include
#include

//函数1,判断string对象是否含有大写字母,无需改变对象的值,所以使用常量引用
bool has_Upper(const string& s)
{
	bool ret = false;
	for (auto c : s)
	{
		if (isupper(c))
		{
			ret = true;
			break;
		}
	}
	return	ret;
}
//函数2,把string对象全部改成小写形式,需要改变对象的值,使用不含const的引用。因为要改变对象的值,所以必须使用引用
void to_Lower(string& s)
{
	for (auto c = s.begin(); c != s.end(); ++c)
	{
		*c = tolower(*c);
	}
}
void test03()
{
	//1.创建string对象
	string s = "cgbweio;Fhbw9p;";
	//2.验证函数1(有一个大写字母F,输出结果为1)
	cout << has_Upper(s) << endl;
	//3.验证函数2(有一个大写字母F,调用函数后变为小写字母f)
	to_Lower(s);
	cout << s << endl;
}
int main()
{
	test03();
	system("pause");
	return 0;
}

编译工具:Visual Studio 2019

运行结果:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/512403.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号