Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

การแปลงสตริงทั้งหมดเป็นตัวพิมพ์ใหญ่หรือเล็กด้วย STL ใน C++


ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อเข้าใจการแปลงสตริงทั้งหมดเป็นตัวพิมพ์ใหญ่หรือตัวพิมพ์เล็กโดยใช้ STL ใน C++

เพื่อทำการแปลงนี้ C++ STL มีฟังก์ชัน toupper() และ tolower() สำหรับแปลงเป็นตัวพิมพ์ใหญ่และตัวพิมพ์เล็กตามลำดับ

ตัวอย่างโค้ด

#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;
}

เอาต์พุต

TUTORIALS POINT
tutorials point