STL-String tips

1. 構(gòu)造函數(shù)

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. 成員函數(shù)

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,000評論 0 23
  • 背景 一年多以前我在知乎上答了有關(guān)LeetCode的問題, 分享了一些自己做題目的經(jīng)驗。 張土汪:刷leetcod...
    土汪閱讀 12,890評論 0 33
  • 我這里有巴菲爾鐵塔 你那里呢 我這里也會下朦朧細雨 你那里呢 我這里一直陽光明媚 你那里呢 我這里的天空偶爾像海 ...
    whoisyou閱讀 282評論 3 3
  • 又被雨困住了,似曾相識的場景。 不能帶耳機是件糾結(jié)的事情,不過還好路上積水并不多,走起來還是沒什么問題。 衣服鞋子...
    Lexchong閱讀 251評論 0 1
  • 我們來講一講微博的隱藏功能 截止2016年9月30日 微博月活躍人數(shù)已達到2.97億 作為2.97億之一 你,會用...
    運營獅訓練營閱讀 8,118評論 0 2

友情鏈接更多精彩內(nèi)容