:: tolower vs std :: tolower difference

I have

using namespace std; vector<char> tmp; tmp.push_back(val); ... 

Now when i try

 transform(tmp.begin(), tmp.end(), tmp.begin(), std::tolower); 

It does not compile, but it compiles:

 transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); 

What is the problem with std::tolower ? It works with one argument, for example, std::tolower(56) compilation. Thanks!

+6
source share
1 answer

std::tolower has two overloads and cannot be resolved for UnaryOperation , where there is no C ::tolower version.

If you want to use std::tolower you can use lambda as

 transform(tmp.begin(), tmp.end(), tmp.begin(), [](unsigned char c) {return std::tolower(c); }); 
+3
source

All Articles