没有合适的资源?快使用搜索试试~ 我知道了~
String类函数用法总结2.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 144 浏览量
2022-10-28
06:11:42
上传
评论
收藏 288KB PDF 举报
温馨提示
试读
6页
。。。
资源推荐
资源详情
资源评论
string 类对象的构造
简化构造函数原型如下(注意,为了简便,把模板中最后一个默认参数省略了):
1: explicit basic_string();
2: string(const char *s);
3: string(const char *s, size_type n);
4: string(const string& str);
5: string(const string& str, size_type pos, size_type n);
6: string(size_type n, E c);
7: string(const_iterator first, const_iterator last);
string 对象的操作
字符串比较
支持六种关系运算符(==、!=、>、>=、<、<=),其采用字典排序策略(与
C 中字符串比较策略完全一样)。这六个关系运算符是非成员的重载运算符。而这些
运算符都支持三种操作数组合:string op string、string op const char*、cons
t char* op string(其中 op 是前面六种关系运算符中任意一种)。解释:提供运算
符的三种重载版本主要是从效率角度考虑的,其避免了临时 string 对象的产生。
另外,string 类还提供了各种重载版本的成员函数 compare 来比较,简化函
数原型为:
1: int compare(const string& str) const;
2: int compare(size_type p0, size_type n0, const string& str);
3: int compare(size_type p0, size_type n0, const string& str, si
ze_type pos, size_type n);
4: int compare(const char* s) const;
5: int compare(size_type p0, size_type n0, const char* s) const;
6: int compare(size_type p0, size_type n0, const char* s, size_t
ype n) const;
返回值:如果调用该函数的对象的比较序列小于操作数比较序列,则返回负数;
若相等,则返回 0;否则,返回正数。
字符串相加
针对 string 类提供了非成员重载 operator+,支持 string 对象之间、string
对象与 const char*对象之间、string 对象与 char 对象之间相加,并且 operator
资源评论
G11176593
- 粉丝: 6664
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功