c++ string uppercase 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: uppercase capitalise character in string c++
str[i] = toupper(str[i]);
Example 3: convert all characters in string to uppercase c++
transform(str.begin(), str.end(), str.begin(), ::toupper);
Example 4: 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 5: toupper c++
int result = toupper(charecterVariable);
char result2 = (char)toupper(variableChar);
Example 6: 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;
}