
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to convert std::string to lower case in C++?
In this section, we will see how to convert all letters of a C++ string to lowercase letters. To do this thing we have to use the transform function. This transform function is present in the algorithm library.
The transform function takes the beginning pointer of the string and the ending pointer of the string. It also takes the beginning of the string to store the result, then the fourth argument is ::tolower. This helps to convert the string into a lowercase string. We can use this same method if we want to convert some string into an uppercase string.
Example Code
#include <iostream> #include <algorithm> using namespace std; int main() { string my_str = "Hello WORLD"; cout << "Main string: " << my_str << endl; transform(my_str.begin(), my_str.end(), my_str.begin(), ::tolower); cout << "Converted String: " << my_str; }
Output
Main string: Hello WORLD Converted String: hello world
- Related Articles
- Convert mixed case string to lower case in JavaScript
- How to convert a string into the lower case using JavaScript?
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- How to convert std::string to LPCSTR in C++?
- How to convert std::string to LPCWSTR in C++?
- Java String to Lower Case example.
- C program to convert upper case to lower and vice versa by using string concepts
- How to convert string to title case in C#?
- How to convert an std::string to const char* or char* in C++?
- How to convert a std::string to const char* or char* in C++?
- How to convert a string to camel case in JavaScript?
- How to convert the character values in an R data frame column to lower case?
- How to check if a string contains only lower case letters in Python?
- How to convert a string into Title Case in Golang?

Advertisements