検索と置換の機能に少し問題がありましたが、すべての文字を置き換えることができますが、禁止された文字に一致する文字を変更するだけです。 見つかったときに文字列ベクトルの特定の文字を置き換えます。C++
はここで、これまでclass getTextData
{
private:
string currentWord;
vector<string> bannedWords;
vector<string> textWords;
int bannedWordCount;
int numWords;
char ch;
int index[3];
ifstream inFile();
public:
void GetBannedList(string fileName);
void GetWordAmount(string fileName);
void GetDocumentWords(string fileName);
void FindBannedWords();
void ReplaceWords(string fileOutput);
};
for(int i = 0; i <= numWords; i++)
{
for(int j = 0; j < bannedWordCount; j++)
{
if(string::npos != textWords[i].find(bannedWords[j]))
{
textWords[i] = "***";
}
}
}
これは単なる*の固定数に置き換えられますが、私はそれはそれは*ない単語全体で見つかった文字を置換したい私のコードです。アドバンス
正規表現(正規表現)を見ましたか? – Tim
'textWords'と' bannedWords'の宣言を投稿できますか? – hmjd
@hmjd宣言を示すために投稿を修正しました。 – bobthemac