mardi 24 novembre 2015

STL containers and algorithm C++

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 tom solve it. I"m learning new to c++ and just started to learn stl and coi

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!

Aucun commentaire:

Enregistrer un commentaire