tolower小写:
函数实现原型:
int tolower(int c)
{
if ((c >= 'A') && (c <= 'Z'))
return c + ('a' - 'A');
return c;
}
通过改变ASCII码进行大小写转换
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
getline(cin,a);
for(int i=0;i<a.size();i++)
{
a[i]= tolower(a[i]);
}
cout<<"转换为小写为:";
for(int i=0;i<a.size();i++)
{
cout<<a[i];
}
}
toupper小写:
函数实现原型:
int toupper(int c)
{
if ((c >= 'a') && (c <= 'z'))
return c + ('A' - 'a');
return c;
}
例:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
getline(cin,a);
for(int i=0;i<a.size();i++)
{
a[i]= toupper(a[i]);
}
cout<<"转换为大写为:";
for(int i=0;i<a.size();i++)
{
cout<<a[i];
}
}