【问题标题】:C++ compile error: has initializer but incomplete typeC++ 编译错误:具有初始化程序但类型不完整
【发布时间】:2012-11-05 20:40:44
【问题描述】:

我在 Eclipse 中编码,并且有如下内容:

#include <ftream>
#include <iostream>

void read_file(){
    char buffer[1025];
    std::istringstream iss(buffer);
}

但是,当我尝试构建时,出现以下错误:variable 'std::istringstream iss' has initializer but incomplete type

有什么快速的想法吗?我用谷歌搜索了一下,似乎大多数有这个问题的人根本没有包含正确的头文件,我相信我做得正确。

【问题讨论】:

  • std::istringstring?不过,它无论如何都在 &lt;sstream&gt; 标头中。
  • 哎呀,我打错了问题,我按照你写的方式编码所以问题还是一样
  • 是的,添加 使其构建正确,谢谢!
  • 很难看出重新打开的理由是什么。我会跳过并让其他人做出决定,但这似乎是一个简单的错误。
  • 另外,我认为第一行应该是#include&lt;fstream&gt; 而不是#include &lt;ftream&gt; @Aneem

标签: c++ compilation istringstream


【解决方案1】:

你需要的包括:

#include <sstream>

【讨论】:

  • 这实际上是标准库中的一个错误;找到了类,但没有找到使程序员对要包含的文件一无所知的方法,除非他牢记标准库文件名,这是一个荒谬的期望。我希望有人将其报告为错误。
  • @jriv 我不确定你在说什么。 cppreference 明确指出必须包含sstream 标头才能使用std::istringstreamen.cppreference.com/w/cpp/io/basic_istringstream
【解决方案2】:

` 请包括以下任何一项:

`#include<sstream>`

using std::istringstream; 

【讨论】:

    猜你喜欢
    • 2011-05-16
    • 1970-01-01
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多