一.初始化

string string1;
string string2="hello world";
string string3("hello world");
string string4(,'h');

二.对象的比较

可以用 <、<=、==、!=、>=、> 运算符比较 string 对象。按照字典序比较字符串的大小。

还可以使用+运算符拼接字符串

string string2="hello ";
string string3("world");
string string4=string2+string3;//hello world

三.求 string 对象的子串

substr 成员函数可以用于求子串 (n, m),函数原型如下:

string substr(int n = , int m = string::npos) const;

调用时,如果省略 m 或 m 超过了字符串的长度,则求出来的子串就是从下标 n 开始一直到字符串结束的部分。

string string1="hello world";
string string2=string1.substr(,);//ello wo
string string3=string1.substr();//ello world

四.string和int的互相转化

1.int转换成string

    string str=to_string(-);//"-12"
string str1=to_string();//"12"
string str2=to_string(-+);//"1"

2.string转换成int

    string str=to_string(-);//"-12"
//先转化为char*型,而后再转化为int
int a=atoi(str.c_str());//-12

最新文章

  1. 3D旋转菜单
  2. javascript遍历数组最优写法
  3. hdu 2141 Can you find it?
  4. [转]ASP.NET MVC 入门5、View与ViewData
  5. [React] React Fundamentals: State Basics
  6. Google为何这么屌
  7. java设计模式---原型模式
  8. QuickReport多页打印
  9. Python beautifulsoup 选择器 select 选择&lt;meta/&gt;等不需要成对结尾标签未写‘/’
  10. Centos7搭建kubernetes搭建
  11. js页面事件方法
  12. PageRank算法--从原理到实现
  13. mssql卸载后重新安装 错误解决
  14. mysql添加字段并且设置默认值
  15. 关于Python veriable scope 的一点疑问
  16. django模板语言和过滤
  17. November 09th, 2017 Week 45th Thursday
  18. MySQL的innoDB锁机制以及死锁处理
  19. 一次性选中word中全部Table
  20. HDU - 3577 Fast Arrangement 线段树

热门文章

  1. 设计模式-Template(行为模式) 采用 继承的方式 将算法封装在抽象基类中,在子类中实现细节。利用面向对象中的多态实现算法实现细节和高层接口的松耦合。
  2. rsync的简介及使用
  3. 使用vmware workstation安装centos 7操作系统
  4. NLP中的数据增强
  5. MS SQL OPENJSON JSON
  6. saltstack--史上最细致安装攻略!亲测无坑
  7. 【STM32H7教程】第19章 STM32H7的GPIO应用之按键FIFO
  8. vue的基础概念和语法01
  9. CAT 默认密码修改
  10. Go文件内容追加问题