c++ character to lowercase code example
Example 1: convert characters to lowercase c++
str[i] = tolower(str[i]);
Example 2: tolower in c++
#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
char str[] = "John is from USA.";
cout << "The lowercase version of \"" << str << "\" is " << endl;
for (int i=0; i<strlen(str); i++)
putchar(tolower(str[i]));
return 0;
}
Example 3: 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;
}
Example 4: convert whole string to lowercase c++
#include<bits/stdc++.h>
using namespace std;
main() {
string s = "Viet Nam";
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
}