C++ stringstream 未在此范围内声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3086949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 12:01:40  来源:igfitidea点击:

stringstream was not declared in this scope

c++stringstream

提问by angela

I'm having problem with stringstream.my visual studio nor linux g++ can understand stingstream. I've added sstream but it does'nt solve anything. I've worked with it before and really don't know what's up with it now?

我在使用 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
}

I'm writing a compiler so the code is the output,that's why it may seams a bit odd.

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

回答by Amardeep AC9MF

If you include #include <sstream>then you must also reference the class by:

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

std::stringstreamor declare using namespace std;before using it.

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

If you post more information we could provide more detailed help.

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

回答by jalf

This code compiles fine for me under G++:

这段代码在 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
}

The only difference is that I removed #include "SymbolTable.cpp", and added a label43.

唯一的区别是我删除了#include "SymbolTable.cpp",并添加了一个label43.

So apparently, if it doesn't work for you, the problem is in some of the code you omitted. The //some code hereparts or in SymbolTable.cpp

显然,如果它对您不起作用,则问题出在您省略的某些代码中。该//some code here零件或SymbolTable.cpp

Of course, it also seems verysuspicious that you're including a cpp file. That is most likely an error.

当然,您包含一个 cpp 文件似乎也可疑。这很可能是一个错误。