Your use of tolower
has undefined behavior! The cppreference page on std::tolower tells you exactly what to do to fix it:
Like all other functions from <cctype>
, the behavior of std::tolower is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:
char my_tolower(char ch) {
return static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
}
Similarly, they should not be directly used with
standard algorithms when the iterator's value type is char or signed
char. Instead, convert the value to unsigned char first:
std::string str_tolower(std::string s) {
std::transform(s.begin(), s.end(), s.begin(),
// static_cast<int(*)(int)>(std::tolower) // wrong
// [](int c){ return std::tolower(c); } // wrong
// [](char c){ return std::tolower(c); } // wrong
[](unsigned char c){ return std::tolower(c); } // correct
);
return s;
}
So your code should look like this:
transform(a.begin(), a.end(), a.begin(), [](unsigned char c) { return std::tolower(c); });
As for your warning, it's due to the warning level you have set for your compiler. You get around it you can explicitly cast the result:
transform(a.begin(), a.end(), a.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});