uppercase to lowercase string c++ code example
Example 1: convert whole string to lowercase c++
#include<bits/stdc++.h>
using namespace std;
main() {
string s = "Viet Nam";
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
}
Example 2: convert letters to uppercase in c++
#include <iostream>
#include <string>
using namespace std;
int main()
{
char letter;
cout << "You will be asked to enter a character.";
cout << "\nIf it is a lowercase character, it will be converted to uppercase.";
cout << "\n\nEnter a character. Press . to stop: ";
cin >> letter;
if(islower(letter))
{
letter = isupper(letter);
cout << letter;
}
while(letter != '.')
{
cout << "\n\nEnter a character. Press . to stop: ";
cin >> letter;
if(islower(letter))
{
letter = toupper(letter);
cout << letter;
}
}
return 0;
}