C++ 异常处理和范围

C++ 异常处理和范围,c++,exception-handling,scope,C++,Exception Handling,Scope,因此,我必须为一个刽子手游戏编写这段代码,我得到了一个dicitonary.txt文件,其中每行包含127k个单词。我所做的是我使用了一个地图字典根据单词的字母数存储单词。我这里有这段代码,但我有几个问题: #include <iostream> #include <map> #include <set> #include <cmath> #include <string> #include <fstream> using

因此,我必须为一个刽子手游戏编写这段代码,我得到了一个dicitonary.txt文件,其中每行包含127k个单词。我所做的是我使用了一个
地图字典
根据单词的字母数存储单词。我这里有这段代码,但我有几个问题:

#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 i = 0; i < 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;
}
提前非常感谢

< P> <代码>图>代码>在C++中,语法上不符合C++。未在此范围内声明错误
“DICTIONARY”
具有误导性,原因是编译器未接受
映射DICTIONARY
作为变量声明,并且未将DICTIONARY添加到标识符表中

将其替换为
map
(注意添加的空格)


。。。或者尝试将代码编译为C++11(如果编译器支持)。C++ 11给C++带来了重大的改进!p> 你能确定这是实际的代码,并附加实际的编译器输出吗?这是实际的代码,我现在就发布输出。代码编译成功了。@vladfrommoskow这很奇怪:/即使是我的g++也会产生更好的错误消息。出于兴趣,你用的是什么编译器?哦,天哪,是的,它起作用了!非常感谢。我在什么地方读过,但完全忘了!再次感谢你!
source.cpp In function 'int main()':
source.cpp:14:24: error: 'DICTIONARY' was not declared in this scope
source.cpp:14:21: error: '>>' should be '> >' within a nested template argument list