I'm trying to take off what the user wants to take off from a sample text.
ie.
Sample Text: Winning Something!!!!111!!!
If the user asks to take out the numbers, it should say "Winning Something!!!!!!!"
but when I run my code, it either only eliminates one of the elements (only if repeating) or two of the elements (again, only if they are the same).
So my code would output: "Winning Something!!!!1!!!"
but let's say that the sample text said: "12345"
it would take them all out
1 2 3 4 5 6 7 8 9 10 11
string num(numbers); //I have a char array for numbers
for (int i = 0; i < copyText.length(); i++) //copyText is a copy of the sample text
{
for (int j = 0; j < 10; j++)
{
if (copyText[i] == num[j])
{
copyText.erase(copyText.begin() + i); //So this should erase the element starting from i.
}
}
}
I've also tried switching it around
1 2 3 4 5 6 7 8 9 10 11
string num(numbers);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < copyText.length(); j++)
{
if (copyText[i] == num[j])
{
copyText.erase(copyText.begin() + i);
}
}
}