【发布时间】:2020-04-11 21:14:10
【问题描述】:
我在 C++11 中有这段代码:
#include <string>
#include <map>
using namespace std;
map<int, string> finalStates =
{
{ 0, "eroare lexicala" },
{ 1, "identificator" }
};
我尝试将其转换为 C++98,例如:
#include <string>
#include <map>
std::map<int, std::string> finalStates;
finalStates.insert( std::pair<int, std:string> (0, "eroare lexicala"));
finalStates.insert( std::pair<int, std:string> (1, "identificator"));
这给了我错误“finalStates”没有命名类型|
请帮忙。
【问题讨论】:
-
向地图中插入内容的代码必须在函数内部。它不能处于声明级别。 C++ 不能以这种方式工作。
-
gives me the error 'finalStates' does not name a type请发布确切的错误消息。您是否尝试在文件范围内调用函数finalStates.insert(?