聚合' std :: stringstream out'有不完整的类型,无法定义[C ++]

时间:2011-04-21 20:47:52

标签: c++ syntax sstream

我是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();

3 个答案:

答案 0 :(得分:23)

你有没有:

#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 <sstream>会导致系统出现与第一次错误完全相同的错误。

答案 1 :(得分:5)

它是小写L而不是1

out << endl;

我认为@Bo是对的,(抱歉并感谢)将其更改为std::stringstream out;

答案 2 :(得分:2)

你好像缺少stringstream的include。最重要的是你有一个错字

out << end1;

应该阅读

out << endl;

l代替1