Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How can you make a string lowercase in c++? Please help.

+1 vote
asked Jan 4, 2023 by codenxn (1,350 points)

1 Answer

0 votes
answered Jan 4, 2023 by Peter Minarik (86,900 points)

You can iterate through all the characters in the string and turn them into their lowercase counterpart via std::tolower() as shown in this discussion.

#include <algorithm>
#include <cctype>
#include <string>

std::string data = "Abc";
std::transform(data.begin(), data.end(), data.begin(), [](unsigned char c){ return std::tolower(c); });
commented Jan 4, 2023 by codenxn (1,350 points)
Can you tell me a shorter way to do it? It's gonna be hard to memorize this
commented Jan 4, 2023 by Peter Minarik (86,900 points)
It's not a poem to memorize. You learn how logically commands and instructions are built up. Check out all the functions involves, such as std::transform, begin(), end(), etc.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...