Why can’t “transform(s.begin(),s.end(),s.begin(),tolower)” be complied successfully?

Let’s look at a list of options starting with the worst and moving to the best. We’ll list them here and discuss them below: transform(cbegin(s), cend(s), begin(s), ::tolower) transform(cbegin(s), cend(s), begin(s), static_cast<int(*)(int)>(tolower)) transform(cbegin(s), cend(s), begin(s), [](const unsigned char i){ return tolower(i); }) The code in your question, transform(s.begin(), s.end(), s.begin(), tolower) will produce an error … Read more

Do I need to cast to unsigned char before calling toupper(), tolower(), et al.?

Yes, the argument to toupper needs to be converted to unsigned char to avoid the risk of undefined behavior. The types char, signed char, and unsigned char are three distinct types. char has the same range and representation as either signed char or unsigned char. (Plain char is very commonly signed and able to represent … Read more

How to convert an instance of std::string to lower case

Adapted from Not So Frequently Asked Questions: #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); }); You’re really not going to get away without iterating through each character. There’s no way to know whether the character is lowercase or uppercase otherwise. If you really hate … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)