/*
练习6.17:
(a)编写一个函数, 判断string对象中是否含有大写字母。
bool is_have_upper_char_in_string(const string &str)
{
for(auto c:str)
if(isupper(c))
return true;
return false;
}
(b)编写另一个函数,把string对象全都改成小写形式。
void change_to_lower(string &str)
{
for(auto &c:str)
if(isupper(c))
c=tolower(c);
}
(c)在这两个函数中,你使用的形参类型相同吗?为什么?
不同:因为第二个函数需要改变实参的值,不能用常量引用。
*/
#include "TouWenJian_6.h"
bool is_have_upper_char_in_string(const string &str)
{
for(auto c:str)
if(isupper(c))
return true;
return false;
}
void change_to_lower(string &str)
{
for(auto &c:str)
if(isupper(c))
c=tolower(c);
}
int main()
{
string str1;
while(cin>>str1)
{
// cout<<is_have_upper_char_in_string(str1)<<endl;
change_to_lower(str1);
cout<<str1<<endl;
}
return 0;
}