📜  cpp 字符串查找所有出现 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:56.239000             🧑  作者: Mango

代码示例2
string str,sub; // str is string to search, sub is the substring to search for

vector positions; // holds all the positions that sub occurs within str

size_t pos = str.find(sub, 0);
while(pos != string::npos)
{
    positions.push_back(pos);
    pos = str.find(sub,pos+1);
}