Previous Page

Make all characters lowercase in a string - C++ console

Copy and Paste the following code into your favorite C++ Integrated Development Environment (IDE) - compile and run.



#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str; // variable for user's input
    int size;   // variable to store size of the string

    cout << "Enter a sentence to make every character lowercase: "
         << endl;// instruct user what to enter

    getline(cin, str);// get user's sentence

    size = str.size();// size of the string

/***************************************************************************************************/

    for(int y = 0; y < size; y++)// this for loop makes everything lower case  
    {
		str[y] = tolower(str[y]);
    }
    
/***************************************************************************************************/

    cout << str << endl;// output the user's sentence in all lower case

   return 0;

}// END MAIN

//END OF CODE