// C++ program to convert whole string to
// uppercase or lowercase using STL.
#include<bits/stdc++.h>
using namespace std;
int main()
{
// su is the string which is converted to uppercase
string su = "Jatin Goyal";
// using transform() function and ::toupper in STL
transform(su.begin(), su.end(), su.begin(), ::toupper);
cout << su << endl;
// sl is the string which is converted to lowercase
string sl = "Jatin Goyal";
// using transform() function and ::tolower in STL
transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
cout << sl << endl;
return 0;
}
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str="Hello World";
int i;
cout<<"The String is:
"<<str;
cout<<endl<<endl;
cout<<"String after uppercase lowercase modification:
";
for(i=0; i < str.length(); i++)
{
//if its uppercase add to its Ascii code 32 to make lowercase
if(str[i]>='A' && str[i]<='Z')
cout<<char(str[i]+32);
// else if its lowercase subtract 32 to make it upper case
else if(str[i]>='a' && str[i]<='z')
cout<<char(str[i]-32);
// else if its a space or symbol for example just print it as is
else cout<<str[i];
//the reason this works is that the distance in Ascii from uppercase to lowercase
//is standard and constant
}
return 0;
}
$cat greekfile | tr “[a-z]” “[A-Z]”