I am writing a program where the user enters 2 strings and the program checsk to see if any characters are in both strings, and if they are, remove them from the first string and print it.
So i have this at the moment, and it's almost working but it seems to be ignoring the first character of the second string. If you enter "computer" and "program", for example, it returns "cpute" instead of "cute".
Anyone have any ideas?
#include <iostream>
#include <string>
using namespace std;
int i;
int j;
string x;
string y;
int main()
{
cout << "\n Enter a word \n";
getline (cin, x);
cout << "\n Enter another word \n";
getline (cin, y);
int z = x.length();
int w = y.length();
for (i = 0; i < z; ++i)
{
for (j = 0; j < w; ++j)
{
if(x[i] == y[j])
{
x.erase (i,1);
}
}
}
cout << "Result:" << x << "\n";
system ("pause");
return 0;
}