c++ tolower
时间: 2023-11-12 12:53:25 浏览: 75
`tolower`是C++中的一个函数,用于将一个字符转换为小写字母形式。它的函数原型如下:
```cpp
int tolower(int c);
```
其中,参数`c`是要转换的字符,返回值是转换后的小写字母形式。
以下是一个示例代码,演示如何使用`tolower`函数将字符串中的所有字符转换为小写字母形式:
```cpp
#include <iostream>
#include <cctype>
#include <string>
int main() {
std::string str = "Hello World";
for (char& c : str) {
c = std::tolower(c);
}
std::cout << str << std::endl; // 输出: hello world
return 0;
}
```
在上述代码中,我们使用了一个循环来遍历字符串中的每个字符,然后使用`tolower`函数将字符转换为小写字母,并将转换后的结果赋值给原字符。最后,输出转换后的字符串。
相关问题
tolower函数c++
tolower函数是C++标准库中的一个函数,它用于将一个字符转换为小写形式。它的函数原型如下:
```cpp
int tolower(int c);
```
该函数接收一个参数 c,表示要转换的字符。它返回一个转换后的字符,如果无法转换,则返回原始字符。
下面是一个使用示例:
```cpp
#include <iostream>
#include <cctype>
int main() {
char c = 'A';
char result = tolower(c);
std::cout << result << std::endl; // 输出 'a'
return 0;
}
```
在上面的示例中,我们将字符 'A' 传递给 tolower 函数进行转换,然后将转换后的字符 'a' 输出到控制台上。
tolower 怎么使用
tolower 是一个 C++ 标准库函数,用于将大写字母转换为小写字母。它的使用方法如下:
```c++
#include <cctype>
#include <iostream>
int main() {
char c = 'A';
std::cout << "Before tolower: " << c << std::endl;
c = tolower(c);
std::cout << "After tolower: " << c << std::endl;
return 0;
}
```
这个程序会输出:
```
Before tolower: A
After tolower: a
```
可以看到,tolower 函数将大写字母 'A' 转换为小写字母 'a'。