在C++中,我们可以使用std::tolower()
函数将字符转换为小写形式。要在循环中使用std::tolower()
函数,我们可以使用一个循环来遍历字符串的每个字符,并将每个字符转换为小写形式。
以下是一个示例循环,使用std::tolower()
函数将字符串中的所有字符转换为小写形式:
#include <iostream>
#include <cctype>
int main() {
std::string str = "Hello World";
for (char &c : str) {
c = std::tolower(c);
}
std::cout << "Lowercase string: " << str << std::endl;
return 0;
}
在上面的示例中,我们使用for
循环遍历字符串str
中的每个字符,并使用std::tolower()
函数将字符转换为小写形式。最后,我们打印出转换后的字符串。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c++ cin.get在循环中怎样用