6

我在使用 stringstream 时遇到问题。我的 Visual Studio 和 linux g++ 都无法理解 stingstream。我添加了 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
}

我正在编写一个编译器,所以代码就是输出,这就是为什么它可能会有点奇怪。

4

2 回答 2

14

如果包含#include <sstream>,则还必须通过以下方式引用该类:

std::stringstreamusing namespace std;在使用前声明。

如果您发布更多信息,我们可以提供更详细的帮助。

于 2010-06-21T17:36:33.200 回答
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 文件似乎也很可疑。这很可能是一个错误。

于 2010-06-21T17:57:33.220 回答