美文网首页
STL-String tips

STL-String tips

作者: yangqi916 | 来源:发表于2017-01-16 15:09 被阅读0次

    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);

    相关文章

      网友评论

          本文标题:STL-String tips

          本文链接:https://www.haomeiwen.com/subject/ffkpbttx.html