Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

Chuyển đổi chuỗi thành chữ hoa/chữ thường dùng STL C++

Chuyển toàn bộ chuỗi thành chữ hoa hoặc chữ thường dùng transform với toupper/tolower.

Ví dụ

#include <bits/stdc++.h>
using namespace std;

int main() {
    string su = "Tutorials point";
    transform(su.begin(), su.end(), su.begin(), ::toupper);
    cout << su << endl;
    string sl = "Tutorials Point";
    transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
    cout << sl << endl;
    return 0;
}

Đầu ra

TUTORIALS POINT
tutorials point