convert whole string to uppercase 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: c++ convert lowercase to uppercase
#include <stdio.h>
#include <ctype.h>
int main ()
{
int i=0;
char str[]="Test String.\n";
char c;
while (str[i])
{
c=str[i];
putchar (toupper(c));
i++;
}
return 0;
}
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: convert from uppercase to lowercase c++
int i = 0;
while(str[i])
{
if(str[i] == std::toupper(str[i]) && std::isalpha(str[i]) == 1024)
str[i]+= 32;
++i;
}