[C++]string類的尋找函數

來源:互聯網
上載者:User

標籤:c   c++基礎   c++   字元流   編程   

string類的尋找函數: int find(char c, int pos = 0) const;//從pos開始尋找字元c在當前字串的位置int find(const char *s, int pos = 0) const;//從pos開始尋找字串s在當前串中的位置int find(const char *s, int pos, int n) const;//從pos開始尋找字串s中前n個字元在當前串中的位置int find(const string &s, int pos = 0) const;//從pos開始尋找字串s在當前串中的位置//尋找成功時返回所在位置,失敗返回string::npos的值 int rfind(char c, int pos = npos) const;//從pos開始從後向前尋找字元c在當前串中的位置int rfind(const char *s, int pos = npos) const;int rfind(const char *s, int pos, int n = npos) const;int rfind(const string &s,int pos = npos) const;//從pos開始從後向前尋找字串s中前n個字元組成的字串在當前串中的位置,成功返回所在位置,失敗時返回string::npos的值 int find_first_of(char c, int pos = 0) const;//從pos開始尋找字元c第一次出現的位置int find_first_of(const char *s, int pos = 0) const;int find_first_of(const char *s, int pos, int n) const;int find_first_of(const string &s,int pos = 0) const;//從pos開始尋找當前串中第一個在s的前n個字元組成的數組裡的字元的位置。尋找失敗返回string::npos int find_first_not_of(char c, int pos = 0) const;int find_first_not_of(const char *s, int pos = 0) const;int find_first_not_of(const char *s, int pos,int n) const;int find_first_not_of(const string &s,int pos = 0) const;//從當前串中尋找第一個不在串s中的字元出現的位置,失敗返回string::npos int find_last_of(char c, int pos = npos) const;int find_last_of(const char *s, int pos = npos) const;int find_last_of(const char *s, int pos, int n = npos) const;int find_last_of(const string &s,int pos = npos) const; int find_last_not_of(char c, int pos = npos) const;int find_last_not_of(const char *s, int pos = npos) const;int find_last_not_of(const char *s, int pos, int n) const;int find_last_not_of(const string &s,int pos = npos) const;//find_last_of和find_last_not_of與find_first_of和find_first_not_of相似,只不過是從後向前尋找

下面附上一個執行個體:

#include<iostream>#include<string>using namespace std;void main(){    string a="0AA00AA00";    char str[]="AA";    int pos=a.find(str,2);    cout<<pos<<endl;}

[C++]string類的尋找函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.