你说我没有';t声明';退出';在范围内? 我试图编译一个老的C++代码库,而不是我编写的,我得到以下错误:
你说我没有';t声明';退出';在范围内? 我试图编译一个老的C++代码库,而不是我编写的,我得到以下错误:,c++,g++,C++,G++,“退出”未在范围中声明。 给出错误的代码位于文本顶部,如下所示: %{ #include "AppHdr.h" #include "libutil.h" #include "levcomp.h" #include <cstdio> #include <cstdlib> int yylex(); extern int yylineno; void yyerror(const char *e) { std::fprintf(stderr, "%s:%d: %s
“退出”未在范围中声明。
给出错误的代码位于文本顶部,如下所示:
%{
#include "AppHdr.h"
#include "libutil.h"
#include "levcomp.h"
#include <cstdio>
#include <cstdlib>
int yylex();
extern int yylineno;
void yyerror(const char *e)
{
std::fprintf(stderr, "%s:%d: %s\n", lc_desfile.c_str(), yylineno, e);
// Bail bail bail.
std::exit(1);
}
如果重要的话,这是一个.ypp文件 了解
std
命名空间。exit()
在
中声明,因此为此添加一个#include
fprintf()
在
中声明,因此也要为此添加一个#include
。如果使用
而不是
,则必须在函数前面加上std::
,或使用命名空间std添加代码>语句。我觉得这个参考非常有用,嗯,它仍然给我带来问题。我试着把#include
、#include
、#include
和#include
放在我前面提到的所有地方,但它们都不起作用。错误也没有改变。使用namspace std和std:
时,无论是单独使用还是不使用,我都进行了研究。这不是瞎猜。我发现的每件事都告诉我,我需要把它们包括进去,而我的问题是,即使我把它们包括进去,它也会吐出同样的错误。
g++ (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.