C++ 地图<;字符[],字符[]>;在flex C++;不';不编译
我正在linux上的vmPlayer中处理flex(.lex文件),我想将sass代码转换为css代码。 我想使用char数组的映射,将sass中的变量与其值进行匹配。由于某些原因,我无法在地图中插入值C++ 地图<;字符[],字符[]>;在flex C++;不';不编译,c++,dictionary,flex-lexer,C++,Dictionary,Flex Lexer,我正在linux上的vmPlayer中处理flex(.lex文件),我想将sass代码转换为css代码。 我想使用char数组的映射,将sass中的变量与其值进行匹配。由于某些原因,我无法在地图中插入值 %{ #include <stdio.h> #include <stdlib.h> #include <string> #include <map> #include<iostream> std::m
%{
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include<iostream>
std::map<char[20], char[20]> dictionary; //MY DICTIONARY,GOOD
%}
%%
s dictionary.insert(std::pair<char[20], char[20]>("bb", "TTTT")); //PROBLEM
%%
%{
#包括
#包括
#包括
#包括
#包括
std::map dictionary;//我的字典,很好
%}
%%
插入(std::pair(“bb”,“TTTT”)//问题
%%
它不编译,并给我错误:
hello.lex:30:84: error: no matching function for call to ‘std::pair<char
[20], char [20]>::pair(const char [3], const char [5])’
ine(toReturn); dictionary.insert(std::pair<char[20], char[20]>("bb",
"TTTT"));
hello.lex:30:84:错误:调用'std::pair::pair(const char[3],const char[5])时没有匹配的函数
ine(toReturn);插入(std::pair(“bb”,
“TTTT”);
一般来说,我不确定我可以在flex上轻松使用哪些C库,以及使用flex时哪些库更可疑。
有语法问题吗生成的C++代码中的问题是:<代码>对(conchchar(3),const char(5))< /> >(这是你的常量字符串的大小)与<代码>对(conchchar(20),const char [20 ])< /> >无关。它只是不同的类型 3种解决方案:
- 为字符数组大小添加模板参数(编辑:无效,因为所有元素的大小都必须相同)
- 如果您只需要插入常量,请使用
char[]
- 或者更好更简单&涵盖所有情况:使用
type,它在构造函数中接受字符数组std::string
%{
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include<iostream>
std::map<std::string, std::string> dictionary; //MY DICTIONARY,GOOD
%}
%%
s dictionary.insert(std::pair<std::string, std::string>("bb", "TTTT"));
%%
%{
#包括
#包括
#包括
#包括
#包括
std::map dictionary;//我的字典,很好
%}
%%
插入(std::pair(“bb”,“TTTT”);
%%
它确实有效,但现在我无法打印它,因为它正在等待char*-->fprintf(yyout,“%s”,dictionary[“bb”]);给我错误:ello.lex:60:47:错误:从类型“std::map::mapped_type{aka std::_cxx11::basic_string}”转换为类型“char*”fprintf(yyout,“%s”,(char*)dictionary[“bb]”无效;尝试<代码> STD::CUT<代码> >可以打印<代码> STD::String 或使用<代码>词典[BB] ] CXString()/Cord>获取char内容。所以你应该把你的问题标记为C++