To capitalize the entire string type string

Asked 2 years ago, Updated 2 years ago, 43 views

Is there a way to capitalize the entire string at once? What I found on Google is char type, but I have to write in string type

type

string c++

2022-09-21 20:56

1 Answers

#include <algorithm>
#include <string>

std::string str = "Hello World";
std::transform(str.begin(), str.end(),str.begin(), ::toupper);

It is in the header and stores the results of the function for all elements in the range in a different range.

Circular is

template< class InputIt, class OutputIt, class UnaryOperation >
OutputIt transform( InputIt first1, InputIt last1, OutputIt d_first,
                    UnaryOperation unary_op );

//or

template< class InputIt1, class InputIt2, class OutputIt, class BinaryOperation >
OutputIt transform( InputIt1 first1, InputIt1 last1, InputIt2 first2, 
                    OutputIt d_first, BinaryOperation binary_op );

This is.

Parameters are

This is

#include <boost/algorithm/string.hpp>
#include <string>

std::string str = "Hello World";
boost::to_upper(str);
std::string newstr = boost::to_upper_copy<std::string>("Hello World");


2022-09-21 20:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.