C++ 弹性cout字符串崩溃
当我试图在flex程序中打印字符串(cout)时,程序会崩溃。 我的.l文件如下所示:C++ 弹性cout字符串崩溃,c++,flex-lexer,C++,Flex Lexer,当我试图在flex程序中打印字符串(cout)时,程序会崩溃。 我的.l文件如下所示: %{ #include <iostream> #include <string> using namespace std; %} %option noyywrap %% . {string str = "hi"; cout << str;} %% int main(){ yylex(); return 0; } %{
%{
#include <iostream>
#include <string>
using namespace std;
%}
%option noyywrap
%%
. {string str = "hi"; cout << str;}
%%
int main(){
yylex();
return 0;
}
%{
#包括
#包括
使用名称空间std;
%}
%选项No yywrap
%%
. {string str=“hi”cout它似乎适用于flex版本2.5.39
您可以使用g++-E对生成的文件进行预处理,并查看输出以查看
{string str = "hi"; cout << str;}
{string str=“hi”;cout和你的g++
版本是什么?我无法在flex 2.5.35
和g++4.9.2
上重现问题。我的g++版本是4.9.3有崩溃日志吗?生成的文件看起来像什么?分而治之。这是生成的文件。第740行是我的cout
。没有崩溃日志…程序只是c皮疹没有任何消息。我已经下载了您生成的文件,它可以用g++4.8.4和clang++3.6编译并运行良好。它输出的“blubhi”与输入中的“blubhi”一样多。valgrind只报告一些与flex缓冲区相关的内存泄漏。因此,您的代码对我来说很好。