Why std::transform doesn't work this way:
std::string tmp = "WELCOME";
std::string out = "";
std::transform(tmp.begin(), tmp.end(), out.begin(), ::tolower);
out is empty!
But this works:
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
I don't want the transformation to happen in-place.
You are writing in out-of-bounds memory, since the range of
out
is smaller than that oftmp
. You can store the result inout
by applyingstd::back_inserter
.As user17732522 pointed out, since it's not legal to take the adress of a standard libary function, it's better to pass over a lamda object that calls
std::tolower
on the character when needed.