Wednesday, 18 September 2013

C++, How do get this function to delete the string stored in the array?

C++, How do get this function to delete the string stored in the array?

I have a delete function that is supposed to delete a string in an array
by writing over it with the previous strings. The look function see's that
Overide matches and should be deleted. But the code i wrote for the loop
in Delete is not removing that first spot in the array that Overide has
taken up, and the output remains unchanged. Also each phrase after + is
being added into the array so four spots are taken in the array, and sorry
i could not make that part look better the formatting screwed it up.
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;

No comments:

Post a Comment