STL-String tips

1. 构造函数

substring constructor
Copies the portion of str that begins at the character position pos and spans len characters (or until the end of str, if either str is too short or if len is string::npos).

string (const string& str, size_t pos, size_t len = npos);

2. 成员函数

  • std::string::substr
    Generate substring
    Returns a newly constructed string object with its value initialized to a copy of a substring of this object.The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).

string substr (size_t pos = 0, size_t len = npos) const;




- [std::string::insert](http://www.cplusplus.com/reference/string/string/insert/)
Inserts additional characters into the [string](http://www.cplusplus.com/string) right before the character indicated by *pos* (or *p*):

  ```c++
string& insert (size_t pos,   size_t n, char c);
  • std::string::replace
    Copies the portion of str that begins at the character position subpos and spans sublen characters (or until the end of str, if either str is too short or if sublen is string::npos).

string& replace (size_t pos, size_t len, const string& str,
size_t subpos, size_t sublen);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,787评论 0 23
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,766评论 0 33
  • 我这里有巴菲尔铁塔 你那里呢 我这里也会下朦胧细雨 你那里呢 我这里一直阳光明媚 你那里呢 我这里的天空偶尔像海 ...
    whoisyou阅读 231评论 3 3
  • 又被雨困住了,似曾相识的场景。 不能带耳机是件纠结的事情,不过还好路上积水并不多,走起来还是没什么问题。 衣服鞋子...
    Lexchong阅读 189评论 0 1
  • 我们来讲一讲微博的隐藏功能 截止2016年9月30日 微博月活跃人数已达到2.97亿 作为2.97亿之一 你,会用...
    运营狮训练营阅读 7,847评论 0 2