I am using this code to replace a letter in a string it works fine but it removes the first letter that i need to keep. I only need a * in the centre of the string but this problem has stumped me.
textWords[i].replace(pos, 2 , 1 , '*');
All the words i am replace the middle character in are three characters long and it always get rid of the first character as well. The replace function is the one used for vectors i did not write it and pos is defined by the code below.
size_t pos = textWords[i].find(bannedWords[j]);
Any help is appreciated.
I believe you are trying to replace the second character from each banned word with an asterisk. You have to call std::string::replace using these arguments:
This way you are removing the second character(pos + 1), and replacing it with one asterisk.
EDIT: As @Dan pointed out, you can also just assign the character: