C++ string类型的相关操作

 

预备知识:

1.     头文件:<cctype>

 

       isalnum()

              checks for an alphanumeric character; it is equivalent to (isal‐

              pha(c) || isdigit(c)).

 

       isalpha()

              checks for an alphabetic character; in the standard "C"  locale,

              it  is  equivalent  to  (isupper(c)  ||  islower(c)).   In  some

              locales, there may be additional characters for which  isalpha()

              is true—letters which are neither upper case nor lower case.

 

       isascii()

              checks  whether  c is a 7-bit unsigned char value that fits into

              the ASCII character set.

 

       isblank()

              checks for a blank character; that is, a space or a tab.

      iscntrl()

              checks for a control character.

 

       isdigit()

              checks for a digit (0 through 9).

 

       isgraph()

              checks for any printable character except space.

 

       islower()

              checks for a lower-case character.

 

       isprint()

              checks for any printable character including space.

 

       ispunct()

              checks for any printable character which is not a  space  or  an

              alphanumeric character.

       isspace()

              checks  for  white-space  characters.   In  the  "C" and "POSIX"

              locales, these are: space,  form-feed  ('/f'),  newline  ('/n'),

              carriage  return ('/r'), horizontal tab ('/t'), and vertical tab

              ('/v').

 

       isupper()

              checks for an uppercase letter.

 

       isxdigit()

              checks for a hexadecimal digits, that is, one of

              0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F.

2.关于size_type:

  string类类型和许多其他库类型都定义了一些配套类型(companion type),通过这些配套类型,库类型的使用就能与机器无关(machine-independent)。

3.任何存储string的size操作结果的变量必须为string::size_type类型。特别重要的是:不要把size的返回值赋给一个int变量。

 

程序清单:

 

编译源程序:

    g++ -o string_test string_test.cpp

执行程序:

   ./string_test

执行结果:

There are 4 characters in Hello,World!!!

hello,world!!!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值