to_upper(): This function is included in the "boost/algorithm/string" library. This library contains some brilliant methods which help in accomplishing string manipulations that are lacking in STL library.
This function "to_upper" is used to convert any given argument string to upper case.
header file:
boost/algorithm/string.hpp
syntax:
to_upper(input , loc);
parameters:
input : an input range
loc : a locale used for conversion
The modification of the string is done in-place if to_upper() is used.
There is another modification present i.e., to_upper_copy() , which takes the same parameters as input, but instead of modifying the string in-place it returns a copy of the modified string while keeping the original string as it is.
SAMPLE CODE:
#include<iostream>
#include<boost/algorithm/string.hpp>
using namespace std;
using namespace boost::algorithm;
int main()
{
string s1,s2,s3,s4;
s1 = "welcome to boost";
s2 = "ITS WRITTEN IN C++";
s3 = "#@ It'S QuItE iNtErEsTiNg **";
s4 = "and its quite fun too!!";
to_upper(s1);
to_upper(s2);
to_upper(s3);
string newString = to_upper_copy(s4);
cout<<s1<<endl;
cout<<s2<<endl;
cout<<s3<<endl;
cout<<"Original string :"<<s4<<endl;
cout<<"Modified string :"<<newString<<endl;
}
OUTPUT:
EXPLANATION:
As we an observe from the above code that to_upper() takes any string as input and irrespective of the case of the original characters, it formats them to upper case. It leaves the special characters and symbols untouched.
Similarly, to_upper_copy() instead of modifying the original string i.e., "s4", it returns the modified string to "newString".
Comments