c++ - Exception Handling and Scope -


so have write code hangman game, , supplied dicitonary.txt file contain 127k words each on separate line. did used map<int, set<string>> dictionary; store words based on letter count. have code here have few issues:

#include <iostream> #include <map> #include <set> #include <cmath> #include <string> #include <fstream>  using namespace std;  int main(){    map<int, set<string>> dictionary;     try{       ifstream file("dictionary.txt");       if(file.is_open()){            string temp_input;            for(int = 0; < 127143; i++){                file >> temp_input;                 dictionary[temp_input.length()].insert(temp_input);            }       }       else throw 404;    }catch(int x){          cout << "error: " << x << " - file not found!" << endl;    }     return 0; } 

but error saying dictionary not defined in scope. know in if(){} etc. stays in it, it's called scope. how should access map?

i assume pointer still don't know how use in scope.

and if show me how instead of using 127.. in if statement less i can use while not end of file or similar?

the error output is:

source.cpp in function 'int main()': source.cpp:14:24: error: 'dictionary' not declared in scope source.cpp:14:21: error: '>>' should '> >' within nested template argument list 

thank in advance!

map<int, set<string>> wasn't syntactically conforming c++ until c++11. error 'dictionary' not declared in scope misleading, reason compiler didn't accept map<int, set<string>> dictionary variable declaration, , didn't add dictionary identifier table.

replace map<int, set<string> > (note added whitespace)

... or try compile code c++11 if compiler supports that. c++11 brings major improvements c++!


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -