Why am I getting an error when running this code? I have added g++ -std=c++11 to the compiler additional options. It says it cannot find
Why am I getting an error when running this code? I have added g++ -std=c++11 to the compiler additional options. It says it cannot find the unresolved include file unorder_map, unable to resolve identifier unordered_map , unable to resolve identifier size, and unable to resolve identifier second. Here is the code:
#include
#include
int main(int argc, char **argv) { unordered_map
//Checking number of arguments if (argc > 2) cerr << "Invalid number of arguments"; docsfile.open(argv[1]); // Checking if file was successfully opened if (docsfile.is_open()) {
while (!docsfile.eof()) { // get a doc from docslist and open it string filename; docsfile >> filename; filename = path_to_corpus + filename; ifstream currfile; currfile.open(filename);
// checking if the corpus file can be opened if (currfile.is_open()) { while (!currfile.eof()) { string currline; currfile >> currline; stringstream cline(currline); string temp;
// read a line , get tokens and increment count while (getline(cline, temp, ' ')) mydict[temp]++; } } else { cerr << "Unable to open corpus file"; } } } else { cerr << "Unable to open docsfile"; }
int size_of_vocab = mydict.size(); int totalwords = 0;
// iterating over all keys for (auto val : mydict) totalwords += val->second;
cout << "Vocabulary Size : " << size_of_vocab << endl; cout << "Total Words : " << totalwords << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started