ISUPUR()和ISLULVER()及其在C++中的应用

在C++中,ISUPURE()和ISLUVER()是用于字符串和字符处理的预定义函数。cstring。h是字符串函数和cctype所需的头文件。h是角色函数所需的头文件。

null

isupper()函数 此函数用于检查参数是否包含任何大写字母,如A、B、C、D、…、Z。

Syntaxint isupper(int x)

C++

// Program to check if a character is in
// uppercase using isupper()
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char x;
cin >> x;
if ( isupper (x))
cout << "Uppercase" ;
else
cout << "Not uppercase." ;
return 0;
}


Input : AOutput : Uppercase
Input : aOutput : Not uppercase

islower()函数 此函数用于检查参数是否包含小写字母,如a、b、c、d、…、z。

Syntaxint islower(int x) 

C++

// Program to check if a character is in
// lowercase using islower()
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char x;
cin >> x;
if ( islower (x))
cout << "Lowercase" ;
else
cout << "Not Lowercase." ;
return 0;
}


Input:AOutput : Not Lowercase
Input : aOutput : Lowercase

islower()、isupper()、tolower()、toupper()函数的应用。 给定一个字符串,任务是将字符串中的字符转换为相反的大小写,也就是说,如果一个字符是小写的,我们需要将其转换为大写,反之亦然。

Syntax of tolower():int tolower(int ch);
Syntax of toupper():int toupper(int ch);

例如:

Input : GeekSOutput :gEEKsInput :Test CaseOutput :tEST cASE

1.逐个字符遍历给定的字符串,直到其长度,使用预定义函数检查字符是小写还是大写。 3.如果是小写,则使用toupper()函数将其转换为大写;如果是大写,则使用tolower()函数将其转换为小写。 4.打印最后一个字符串。

C++

// C++ program to toggle cases of a given
// string.
#include <iostream>
#include <cstring>
using namespace std;
// function to toggle cases of a string
void toggle(string& str)
{
int length = str.length();
for ( int i = 0; i < length; i++) {
int c = str[i];
if ( islower (c))
str[i] = toupper (c);
else if ( isupper (c))
str[i] = tolower (c);
}
}
// Driver Code
int main()
{
string str = "GeekS" ;
toggle(str);
cout << str;
return 0;
}


输出:

gEEKs

本文由 阿尤什·萨克塞纳 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享