You can use std::back_inserter in <iterator>, although providing the size in front is more efficient. For example:
string str = "hello world!", result;
transform(str.begin(), str.end(), back_inserter(result), ::toupper);
// result == "HELLO WORLD!"