这应该返回一个包含所有 word1 参数的向量,其中包含 sub 作为子字符串,但我不断收到错误“第 779 行向量下标超出范围”
vector<string> search(int num1, string sub, string word1 ...)
{
va_list arguments;
string pword = "";
pword.assign(word1);
vector<std::string> vec;
vec.push_back(sub);
vec[0] = sub;
va_start(arguments, word1);
for (int i = 1; i <= num1; i++)
{
for(int x = 0; x < pword.length(); x++)
{
for(int y = 0; y < sub.length(); y++)
{
if(y+x < pword.length())
{
if(pword[y+x] == sub[y])
continue;
else
break;
}
else
break;
vec.push_back(pword);
}
}
pword = va_arg(arguments, string);
}
va_end(arguments);
return vec;
}