c++ - Convert string to all uppercase leters with std::transform -
i'm using transform algorithm , std::toupper achieve this, can done in 1 line, ?
transform(s.begin(), s.end(), ostream_iterator<string>(cout, "\n"),std::toupper);
i error on this, have make unary function , call transform or can use adaptors ?
use ostream_iterator<char>
instead of ostream_iterator<string>
:
transform(s.begin(),s.end(),ostream_iterator<char>(cout,"\n"),std::toupper);
std::transform
transforms each character , pass output iterator. why type argument of output iterator should char
instead of std::string
.
by way, each character printed on newline. want? if not, don't pass "\n"
.
--
note : may have use ::toupper
instead of std::toupper
.
see these
- http://www.ideone.com/x6fb5 (each character on newline)
- http://www.ideone.com/rcekn (all characters on same line)
Comments
Post a Comment