+ 5

How to use tolower() in C++?

To convert a string from uppercase to lowercase, tolower() function is a way. I wanna know about its header files and uses of this function.

22nd Nov 2020, 6:19 AM
Misbah Ahmed
Misbah Ahmed - avatar
13 ответов
+ 3
Misbah Ahmed even std libraries rely on each other. so, it’s not surprising that you didn’t need tolower() with std::transform(). writing a library function without header is bad programming practice. always include headers for specific functions even if they are visible to your code through other headers. Alphin K Sajan btw tolower() doesn’t convert a string to a lowercase, rather it flips any uppercase char to lowercase.
22nd Nov 2020, 1:28 PM
Flash
+ 8
Misbah Ahmed Actually U need to include either <cctype> (c++) or <ctype.h> (c) to use functions like tolower()....
22nd Nov 2020, 6:43 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
tolower() is used to convert uppercase characters to lowercase . It is defined in <cctype> header file For more reference check this out: https://www.programiz.com/cpp-programming/library-function/cctype/tolower
22nd Nov 2020, 6:30 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 7
Flash Nice catch....
22nd Nov 2020, 1:49 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 6
If u used it so , then consider it a bad practise.. Idk , Maybe it have worked bcos of the iostream header file ...
22nd Nov 2020, 6:37 AM
Alphin K Sajan
Alphin K Sajan - avatar
+ 4
Misbah Ahmed can you share you entire code here showing such behaviour
22nd Nov 2020, 7:10 AM
Arsenic
Arsenic - avatar
+ 4
Misbah Ahmed I was told that some headers are included out of our consent as we include some headers. That is because the code in the included header needed the functionality provided by the other header we did not explicitly include. https://www.sololearn.com/post/69831/?ref=app
22nd Nov 2020, 7:14 AM
Ipang
0
But I used it with the function transform() and didn't need <cctype> header!!!
22nd Nov 2020, 6:31 AM
Misbah Ahmed
Misbah Ahmed - avatar
0
Nope, I included <algorithm> header for transform() function. And in the transform function, I used tolower as an argument without a parenthesis beside the tolower.
22nd Nov 2020, 6:40 AM
Misbah Ahmed
Misbah Ahmed - avatar
0
Like so, transform(variable_name.begin(), variable_name.end(), variable_name.begin(), tolower)
22nd Nov 2020, 6:41 AM
Misbah Ahmed
Misbah Ahmed - avatar
0
I think you should use #include<string> to work with string data types.
23rd Nov 2020, 2:25 PM
Ehsan
Ehsan - avatar
0
you can convert a string to lower without using tolower() function.
24th Nov 2020, 12:44 AM
Anup Barua
Anup Barua - avatar