Hey, I am doing some programming exercises, it is to read in a txt file and then read in a list of banned words in an array. I've managed to do this but the last step requires me to filter the original text file with the banned words and change them to stars e.g.
one of the banned words is "dog", when this comes up in the textFile1 anywhere that it says dog should change to "***".
ive seen something where you would put textFile1.replace(textFile1.find("dog"), "***" but its not using the array so I dont understand how to filter using the array i made.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
fstream textFile1;
textFile1.open("text1.txt", ios::in);
if (textFile1.is_open())
{
string line;
while (getline(textFile1, line)) {
cout << line << endl;
}
textFile1.close();
}
string bannedWords[100];
int i = 0;
ifstream bannedFile("banned.txt");
if (bannedFile)
{
while ((bannedFile >> bannedWords[i]) && (i < 100))
{
i++;
}
}
else
{
cout << "Unable to open file" << endl;
exit(0);
}
for (i = 0; i < 8; i++) {
cout << bannedWords[i] << endl;
}
}