string類中的find函式

2021-07-31 10:14:55 字數 627 閱讀 8811

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的值

例如: string temp=s[j]+s[j];  //定義乙個string型別的變數

if((temp.find(s[i]))==string::npos)   //如果變數temp裡面沒有s[i]的字串,則輸出string::npos的值

step+=temp.find(s[i]); //輸出s[i]在temp的位置 

C語言string中的find 函式

在c 中,字串型別string後面加上.find 的作用,是 string str1,str2 int i string str1 qwertyuuoesdi string str2 uu char c q i str1.find str2 從串str1中查詢時str2,返回str2中首個字元在st...

string中的find 函式返回值

1905111 求和1到2019中含有2019數字的和 include include using namespace std intmain cout include include using namespace std intmain cout 以上兩種方式產生的答案都是相同的,但是這裡fin...

String類中的基本函式

需要了解的 知識 1.1使用 比較 比較物件是否引用同一塊記憶體,是則返回true,否則返回false 1.2使用equals 函式比較 比較string值是否相同,equals equalsignorecase 用於對兩個字串的內容進行等價性檢查。equalsignorecase 方法忽略字串大小...