常用C++函数

  • 处理判断字符类

    • isalpha:判断字符是否为字母

      • 返回值:是字母返回非零,不是字母返回零

      • 使用

        1
        2
        
        cout<<isalpha('a'); //返回非零
        cout<<isalpha('2'); //返回0
        
    • isalnum:判断是否为字母或数字

      1
      2
      3
      
      cout<<isalnum('a'); //输出非零
      cout<<isalnum('2'); // 非零
      cout<<isalnum('.'); // 零
      
    • islower:判断是否是小写字母

      1
      2
      3
      
      cout<<islower('a'); //非零
      cout<<islower('2'); //输出0
      cout<<islower('A'); //输出0
      
    • isupper:判断是否是大写字母

      1
      2
      3
      
      cout<<isupper('a'); //返回0
      cout<<isupper('2'); //返回0
      cout<<isupper('A'); //返回非零
      
    • tolower:把字符转化为小写

      1
      2
      3
      
      string str= "THIS IS A STRING";
      for (int i=0; i <str.size(); i++)
         str[i] = tolower(str[i]);
      
    • toupper:把字符转化为大写

      1
      2
      3
      
      string str= "hahahahaha";
      for (int i=0; i <str.size(); i++)
         str[i] = toupper(str[i]);
      
0%