
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements