方法一: #include <algorithm>#include <string>using namespace std; int main()
{ string str="Annotated
Bibliography on Data Design"; transform(str.begin(),str.end(),str.begin(),tolower);return 0;
}
方法二: #include <string>#include <iostream>using namespace std; int main()
{ stringstr("Annotated
Bibliography on Data Design"); for(unsigned int i=0;i<str.size();++i)
str[i]=tolower(str[i]);
cout<<str; return 0;
}
存有疑虑的是:为什么直接使用str.toLowerCase() 就不行呢,提示错误:toLowercase不是str的成员函数,这是为何呢?
本文介绍了两种在C++中将字符串转换为全小写的方法:一种利用了标准库中的<algorithm>和<string>头文件;另一种则通过遍历字符串并应用tolower函数实现。此外,还解答了一个常见疑问:为何不能直接调用str.toLowerCase()。
3121

被折叠的 条评论
为什么被折叠?



