str to lower/upper case

//////TO UPPER////// 

// Online C++ compiler to run C++ program online

#include <iostream>

#include<string>

#include<algorithm>

using namespace std;

int main() {

    // Write C++ code here

   string str="AbcdAFF";

  // cout<<'a'-'A';

   for (int i=0;i<str.size();i++){

       if(str[i]>='a'&&str[i]<='z'){

           str[i]=str[i]-32;

       }

   }

   cout<<str;


    return 0;

}

///////TO LOWER////////

// Online C++ compiler to run C++ program online

#include <iostream>

#include<string>

#include<algorithm>

using namespace std;

int main() {

    // Write C++ code here

   string str="AbcdAFF";

  // cout<<'a'-'A';

   for (int i=0;i<str.size();i++){

       if(str[i]>='A'&&str[i]<='Z'){

           str[i]=str[i]+32;

       }

   }

   cout<<str;


    return 0;

}

///////////STL fn

// Online C++ compiler to run C++ program online

#include <iostream>

#include<string>

#include<algorithm>

using namespace std;

int main() {

    // Write C++ code here

   string str="AbcdAFF";

  transform(str.begin(),str.end(),str.begin(),::toupper);

  cout<<str<<endl;

  transform(str.begin(),str.end(),str.begin(),::tolower);

  cout<<str;


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings