C++ 不允许不完整的类型:stringstream

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5781597/
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 18:52:52  来源:igfitidea点击:

Incomplete type is not allowed: stringstream

c++typesstringstream

提问by pighead10

Why does this line give the error Error: incomplete type is not allowed?

为什么这一行会给出错误Error: incomplete type is not allowed

stringstream ss;

回答by Prasoon Saurav

#include <sstream>and use the fully qualified name i.e. std::stringstream ss;

#include <sstream>并使用完全限定名称,即 std::stringstream ss;

回答by ybungalobill

Please, add:

请加:

#include <sstream>

回答by rakslice

An incomplete typeerror is when the compiler encounters the use of an identifier that it knows is a type, for instance because it has seen a forward-declaration of it (e.g. class stringstream;), but it hasn't seen a full definition for it (class stringstream { ... };).

一个incomplete type错误是,当编译器遇到使用它知道一个标识符是一种类型,例如,因为它已经看到了它(如向前声明class stringstream;),但目前还没有看到一个完整的定义是(class stringstream { ... };)。

This could happen for a type that you haven't used in your own code but is only present through included header files -- when you've included header files that use the type, but not the header file where the type is defined. It's unusual for a header to not itself include all the headers it needs, but not impossible.

对于您未在自己的代码中使用但仅通过包含的头文件存在的类型,可能会发生这种情况——当您包含使用该类型的头文件,但未包含定义该类型的头文件时。标头本身不包含它需要的所有标头是不寻常的,但并非不可能。

For things from the standard library, such as the stringstreamclass, use the language standard or other reference documentation for the class or the individual functions (e.g. Unix manpages, MSDN library, etc.) to figure out what you need to #includeto use it and what namespace to find it in if any. You may need to search for pages where the class name appears (e.g. man -k stringstream).

对于来自标准库的东西,例如stringstream类,使用类或单个函数的语言标准或其他参考文档(例如 Unixman页面、MSDN 库等)来确定您需要#include使用它的内容以及使用它的内容如果有的话,可以在命名空间中找到它。您可能需要搜索出现类名的页面(例如man -k stringstream)。