我有一个删除函数,它应该通过用以前的字符串覆盖它来删除数组中的一个字符串。Look 函数看到 Overide 匹配并应该被删除。但是我为 Delete 中的循环编写的代码并没有删除 Overide 占用的数组中的第一个点,并且输出保持不变。此外,+ 之后的每个短语都被添加到数组中,因此在数组中占据了四个位置,抱歉,我无法使该部分看起来更好,格式搞砸了。
int AR::Look(const std::string & word)
{
int result = -1;
for(int i=0; i<counter; ++i)
{
if( con[i].find(word) != std::string::npos)
result = i;
}
return result;
}
void AR::Delete(const string & word)
{
int loc = Look(word);
if (loc == -1)
{
cout<<"word not found\n";
}
else
{
for(int i=0; i<counter-1,i++;)
{
con[i]= con[i+1];
}
}
}
AR their
Ar(1);
theirAr + "Overload the +" + " operator as a member function " + "with chaining to add a string " + "to an Arrary object.";
cout<<theirAr<<endl<<endl;
cout<<"testing Delete and Look. <<endl;
theirAr.Delete("XXXXXX");
theirAr.Delete("Overload");
cout<<"Output after Delete and Look called\n";
cout<<theirArray<<endl<<endl;