如何在C ++中将std :: string转换为小写?
在本节中,我们将看到如何将C++字符串的所有字母转换为小写字母。为此,我们必须使用transform函数。该变换函数存在于算法库中。
转换函数采用字符串的开始指针和字符串的结束指针。它还使用字符串的开头来存储结果,然后第四个参数是::tolower。这有助于将字符串转换为小写字符串。如果要将字符串转换为大写字符串,可以使用相同的方法。
范例程式码
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string my_str = "Hello WORLD";
cout << "Main string: " << my_str << endl;
transform(my_str.begin(), my_str.end(), my_str.begin(), ::tolower);
cout << "Converted String: " << my_str;
}输出结果
Main string: Hello WORLD Converted String: hello world
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短