Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include

#include using namespace std;

int main(int argc, char **argv) { unordered_map mydict; // Map to store frequency of tokens ifstream docsfile; string path_to_corpus = "/home/bravosad/public_html/cse278/docs"; // Mention path to the corpus here ending with a /

//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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

7. Discuss how measuring cohesion has developed via questionnaires.

Answered: 1 week ago

Question

Find dy/dx if x = te, y = 2t2 +1

Answered: 1 week ago