stringstream在此范围内未声明。

6

我遇到了stringstream的问题。我的Visual Studio和Linux g++都无法理解stringstream。我已经添加了sstream,但没有解决任何问题。我以前曾经使用过它,但现在真的不知道出了什么问题?

#include <sstream>
#include <stdlib.h>
#include "SymbolTable.cpp"
#include "setjmp.h"
using namespace std;
jmp_buf *bfj;
int TOP , SP=3 ;
struct types{int int_val;float float_val;char char_val;bool bool_val;};

types DS[6400];
int main(){
...//some code here
label38 : stringstream s;
label39 : bfj = (jmp_buf *)"label65";
label40 : longjmp(*bfj,1);;
label41 : goto label43;
label42 : TOP=SP;
//some code here
}

我正在编写一个编译器,因此代码是输出结果,这就是为什么它可能看起来有点奇怪。

这个对我来说可以编译。你有收到其他的错误或警告吗?你确定你在使用 C++ 编译器 (g++),而不是 C 编译器 (gcc) 吗? - Tyler McHenry
2个回答

14
如果您包含了#include <sstream>,那么您必须使用以下方式引用该类: std::stringstream或在使用它之前声明using namespace std;
如果您发布更多信息,我们可以提供更详细的帮助。

@angela:你已经在你发布的代码片段中有了那个。 - jalf

2

这段代码在我的G++编译器下可以顺利编译:

#include <sstream>
#include <stdlib.h>
#include "setjmp.h"
using namespace std;
jmp_buf *bfj;
int TOP , SP=3 ;
struct types{int int_val;float float_val;char char_val;bool bool_val;};

types DS[6400];
int main(){
label38 : stringstream s;
label39 : bfj = (jmp_buf *)"label65";
label40 : longjmp(*bfj,1);;
label41 : goto label43;
label42 : TOP=SP;
label43 : (void)0;
//some code here
}

唯一的区别是我删除了#include "SymbolTable.cpp",并添加了一个label43
因此,显然,如果对您不起作用,则问题在于您省略的某些代码。 //some code here部分或SymbolTable.cpp中的代码。
当然,您包含cpp文件也似乎非常可疑。这很可能是一个错误。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接