I need to convert only letters in the string to uppercase and tried this piece of code which throws an error.
s = "Dense-123-Sparse-999"
std::transform(s.begin(), s.end(), s.begin(), std::toupper);
Expected Output: "DENSE-123-SPARSE-999"
"Error: non-void lambda does not return a value in all control paths [-Werror,-Wreturn-type]"
It's throwing an error since there are digits in the input string. How do I write a lambda function that converts characters to uppercase only if they are an alphabet and not a number?
something like this,
transform_if(s.begin(), s.end(), s.begin, [](char c){ if(isalpha(c)return toupper(c);});
since C++ doesnt have transform_if, i'm looking for a one liner with any other commands.