xxxxxxxxxx
std::string data = "This is a sample string.";
// convert string to upper case
std::for_each(data.begin(), data.end(), [](char & c){
c = ::toupper(c);
});
xxxxxxxxxx
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s = "Viet Nam";
transform(s.begin(), s.end(), s.begin(), ::toupper); //uppercase
cout << s << endl;
return 0;
}
xxxxxxxxxx
#include <iostream>
#include <cctype> //toupper()
#include <string> //length()
using namespace std;
int main(){
string text = "uppercase";
cout<<"before :"<<text<<endl;
cout<<"after :";
for(int i = 0; i < text.length();i++){
text[i]=(char)toupper((int)text[i]); //we assign uppercase letter one by one in variable
}
//we show the uppercase letter
cout<<text;
}
/* output
before :uppercase
after :UPPERCASE */
xxxxxxxxxx
int result = toupper(charecterVariable);// return the int that corresponding upper case char
//if there is none then it will return the int for the original input.
//can convert int to char after
char result2 = (char)toupper(variableChar);