[C++STDlib基础]关于单字符的操作——C++标准库头文件

时间:2023-03-08 15:38:14

网上实例

总结

/*
_STD_BEGIN
using _CSTD isalnum; using _CSTD isalpha; using _CSTD iscntrl;
using _CSTD isdigit; using _CSTD isgraph; using _CSTD islower;
using _CSTD isprint; using _CSTD ispunct; using _CSTD isspace;
using _CSTD isupper; using _CSTD isxdigit; using _CSTD tolower;
using _CSTD toupper;
_STD_END 共13个函数:这些函数都是 int Fun(int c);这种形式 isdigit(数字)0123456789;islower(小写);isupper(大写);
isxdigit(16进制数)(0~9,a~f,A~F);isalnum(数字字母)(0~9,a~z,A~Z)
*/

实例

#include <conio.h>
#include <cctype>
#include <iostream>
using namespace std;
void test0()
{
int i=0;
char str[]="first line \n second line \n";
while (!iscntrl(str[i]))
{
putchar (str[i]);//first line
i++;
}
}
/*
int tolower ( int c );
int toupper ( int c );
*/
void test1()
{
int i=0;
char str[]="Test String.\n";
char c;
while (str[i])
{
c=str[i];
putchar (tolower(c)); //test string.
i++;
}
i=0;
while (str[i])
{
c=str[i];
putchar (toupper(c));//TEST STRING.
i++;
}
puts(str);//Test String.
}
void Test(char h)
{
cout<<"press key===="<<h<<endl;
switch(h)
{
case '0': test0();break;
case '1': test1();break;
case 27:
case 'q':exit(0);break;
default:cout<<"default "<<h<<endl;break;
}
}
void main()
{
while(1)
{
Test(getch());
}
}