uppercase string c++ code example
Example 1: convert whole string to uppercase c++
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s = "Viet Nam";
transform(s.begin(), s.end(), s.begin(), ::toupper);
cout << s << endl;
return 0;
}
Example 2: convert all characters in string to uppercase c++
transform(str.begin(), str.end(), str.begin(), ::toupper);
Example 3: string to upper c++
std::string data = "This is a sample string.";
std::for_each(data.begin(), data.end(), [](char & c){
c = ::toupper(c);
});
Example 4: toupper c++
int result = toupper(charecterVariable);
char result2 = (char)toupper(variableChar);
Example 5: c++ toupper string
#include <iostream>
#include <string>
#include <locale>
int main ()
{
std::locale loc;
std::string str="Test String.\n";
for (std::string::size_type i=0; i<str.length(); ++i)
std::cout << std::toupper(str[i],loc);
return 0;
}