I am not able to understand why we need double colon for the function. Passing the function alone does not work. Are these object functors? Any explanation is greatly appreciated :)
It's because std::transform needs to know where to find the tolower() function which is in the global namespace. Prepending a scope resolution operator(::) with no namespace given just means to look in the global namespace.
I do not favour using deprecated features in any code that is freshly written.
Use of <ctype.h> (or any of the other C headers) is deprecated in C++.
This is what I strongly favour: #include <cctype> and then use a range-based loop
1 2
std::string str = "HELLO!" ;
for( char& c : str ) c = std::tolower(c) ;
If for some reason (homework?) std::transform must be used, a lambda expression comes in handy: std::transform( str.begin(), str.end(), str.begin(), []( char c ) { return std::tolower(c) ; } ) ;