[問題] 關於string 的 find 函數

看板C_and_CPP (C/C++)作者 (funnymean)時間15年前 (2010/10/30 18:40), 編輯推噓1(102)
留言3則, 3人參與, 最新討論串1/1
網頁上的範例 string str1="There are two needles in this haystack with needles."; string str2="needle"; size_t found; found=str.find(str2); if(found!=string::npos) cout<<"first 'needle' found at: "<<int(found)<<endl; 到這邊我都還看的懂 found=str.find("needles are small",found+1,6) if(found!=string::npos) cout<<"second 'needle' found at: "<<int(found)<<endl; 這個我就看不懂了 他的 "needles are small",found+1,6 是哪裡來的... 三格的用處分別是什麼 謝謝指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.123.5

10/30 18:50, , 1F
found+1是從第一個needle的'e'開始找,6是"needle"長度
10/30 18:50, 1F

10/30 18:54, , 2F
are small可以當作沒看到
10/30 18:54, 2F

10/30 18:57, , 3F
那我可以在" 裡面打隨便的東西都可以嗎??
10/30 18:57, 3F
文章代碼(AID): #1Co_OTQj (C_and_CPP)
文章代碼(AID): #1Co_OTQj (C_and_CPP)