(轉載)C++ string中find() ,rfind() 等函數 用法總結及樣本

來源:互聯網
上載者:User

標籤:找對象   size   其他   函數   not   font   字元   對象   --   

string中 find()的應用  (rfind() 類似,只是從反向尋找)原型如下:(1)size_t find (const string& str, size_t pos = 0) const;  //尋找對象--string類對象(2)size_t find (const char* s, size_t pos = 0) const; //尋找對象--字串(3)size_t find (const char* s, size_t pos, size_t n) const;  //尋找對象--字串的前n個字元(4)size_t find (char c, size_t pos = 0) const;  //尋找對象--字元 結果:找到 -- 返回 第一個字元的索引     沒找到--返回   string::npos  其他還有  find_first_of(), find_last_of(), find_first_not_of(), find_last_not_of()作用是尋找   字串中 任一個字元 滿足的尋找條件string snake1("cobra");int where = snake1.find_first_of("hark");返回3  因為 "hark"中 各一個字元 在 snake1--cobra 中第一次出現的是  字元‘r‘(3為 cobra 中‘r‘的索引)同理:int where = snake1.find_last_of("hark");返回4  因為 "hark"中 各一個字元 在 snake1--cobra 中最後一次出現的是  字元‘a‘(3為 cobra 中‘r‘的索引)

(轉載)C++ string中find() ,rfind() 等函數 用法總結及樣本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.