I been stumped on a problem for a while. I can't seem to check a text file with a set of excluded words before inputing it into a map container. I tried many things but it just can't seem to solve it. I'm new to C++ and just started to learn STL and containers.
using namespace std;
//checking I know is wrong but I do not know how to compare the pair with the set.
bool checking(pair<string, int> const & a, set<string> const &b) {
return a.first != b;
}
void print(pair<string, int> const & a) {cout << a.first << " " << a.second << endl;}
int main() {
ifstream in("document.txt");
ifstream exW("excluded.txt");
map<string, int> M;
set<string> words;
copy(istream_iterator<string>(exW),
istream_iterator<string>(),
inserter(words, begin(words)));
//Need to exlclude certain words before copying into a Map
// CAN NOT USE FOR LOOP
//I cant seem to get the predicate right.
copy_if(istream_iterator<string>(in),
istream_iterator<string>(),
[&](const string & s) { M[s]++;},
checking);
for_each(begin(M),
end(M),
[](pair<string, int> const & a)
{
cout << a.first << " " << a.second << endl;
}
);
return 0;
}
Any tips or advice word be great!