【问题标题】:aggregate 'std::stringstream out' has incomplete type and cannot be defined [C++] [closed]聚合 'std::stringstream out' 的类型不完整,无法定义 [C++] [关闭]
【发布时间】:2011-04-21 20:47:52
【问题描述】:

我是 C++ 新手,请帮我找出问题所在

string c;
stringstream out; //aggregate 'std::stringstream out' has incomplete type and cannot be //defined
out << it->second;
out << end1;//'end1' was not declared in this scope
c = out.str();

【问题讨论】:

    标签: c++ syntax sstream


    【解决方案1】:

    你有没有:

    #include <sstream>
    

    另外,倒数第二行应该是endl(nb:小写L)而不是end1(第一行)。

    以下代码在 MacOS X 上与 G++ 4.2.1 一起编译并正常工作

    #include <iostream>
    #include <sstream>
    
    int main() {
            std::stringstream out;
            out << "foo" << std::endl;
            std::string c = out.str();
            std::cout << c;
    }
    

    省略 #include &lt;sstream&gt; 在我的系统上会导致与您的第一个错误完全相同的错误。

    【讨论】:

      【解决方案2】:

      这是一个小写的L 而不是1

      out << endl;
      

      我觉得@Bo 是对的,(对不起,谢谢)改成std::stringstream out;

      【讨论】:

      • 这是第二个错误,谢谢,字符串流呢?
      • stringstream 是超类,不能直接使用。请改用istringstreamostringstream
      • stringstream 非常好用,您只需调用它std::stringstream
      • 他显然已经导入了命名空间,否则错误会有所不同。
      • 我认为他不需要 std::stringstream。相反,我认为他缺少标题 .
      【解决方案3】:

      您似乎缺少 stringstream 的包含。最重要的是你有一个错字

      out << end1;
      

      应该读

      out << endl;
      

      l 而不是1

      【讨论】:

      • 对不起,我看不出有什么不同
      • 我更新了我的答案以使其更清晰。字体很难看出区别,但确实有区别。
      猜你喜欢
      • 2012-07-29
      • 2014-05-20
      • 2021-06-24
      • 2020-02-21
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多