[Solved] program to delete certain text which is predefined in another file from a file in c++


Show some research effort when you post a question here.

#include <iostream>
#include <unordered_set>
#include <fstream>

int main()
{
    std::unordered_set<std::string> mySet;

    std::string word;
    std::ifstream file1("myFile1.txt");
    if(file1.is_open())
    {
        while(file1 >> word)
            mySet.emplace(word);
        file1.close();
    }

    std::ifstream file2("myFile2.txt");
    if(file2.is_open())
    {
        while(file2 >> word)
        {
            auto look = mySet.find(word);
            if(look != mySet.cend())
                mySet.erase(look);
        }
        file2.close();
    }

    std::ofstream outputFile("Out.txt");
    if(outputFile.is_open())
    {
        for(const auto &it: mySet)
            outputFile << it << '\n';
        outputFile.close();
    }

    return 0;
}

EDIT:

I don’t know what do you mean by not working. just debug your code, before you write the final set of strings to the output file, that’s what I can say.
Just use the following and see what do you get:

for(const auto &it: mySet)
        std::cout << it << '\n';

For instance I am getting the requeried output what do you mentioned in the picture.

Here is my console output:
enter image description here

0

solved program to delete certain text which is predefined in another file from a file in c++