STL(三)string

  • 定义:
    • 字符串容器
    • 模板类basic_string 实例:typedef basic_string<char> string;
    • wstring同样为basic_string 实例,因此与string有类似的操作方式。
  • 操作(捡几个比较常用的):
    • char*--->string
      • 构造函数:string ( const char * s, size_t n ); string ( const char * s );
      • +操作符:string& operator+= ( const char* s );
      • append函数:string& append ( const char* s, size_t n ); string& append ( const char* s );
      • insert函数:string& insert ( size_t pos1, const char* s, size_t n); string& insert ( size_t pos1, const char* s );
    • string---->char*
      • c_str:const char* c_str ( ) const;(返回一const字符串指针,可进行字符串拷贝、比较等操作)
      • data:const char* data() const;(返回一const字符指针,无字符串尾)
      • copy函数:size_t copy ( char* s, size_t n, size_t pos = 0) const;(只是拷贝内容,没有添加字符串尾)
    • 添加字符:
      • push_back函数:void push_back ( char c );
      • +操作符:string& operator+= ( char c );
    • 删除字符(咋就没提供一个类似push_back的删除函数呢?):
      • erase函数:iterator erase ( iterator position );
    • 未完待续。。。

转载于:https://www.cnblogs.com/dahai/archive/2012/06/02/2532081.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值