I'm using transform algorithm and std::toupper to achieve this, but can this be done in one line, like this ?
transform(s.begin(), s.end(), ostream_iterator<string>(cout, "\n"),std::toupper);
I get error on this, so do I have to make a unary function for this and call it with transform or I can use some adaptors ?
The toUpperCase() method converts a string to upper case letters.
C++ String has got built-in toupper() function to convert the input String to Uppercase.
The strtoupper() function converts a string to uppercase.
If lowercase, convert it to uppercase using toupper() function, if uppercase, convert it to lowercase using tolower() function.
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 and pass it to the output iterator. That is why the type argument of the output iterator should be char
instead of std::string
.
By the way, each character will be printed on a newline. Is that what you want? If not, don't pass "\n"
.
--
Note : You may have to use ::toupper
instead of std::toupper
.
See these
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With