聚合“std::stringstream out”的类型不完整,无法定义 [C++]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5749644/
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
aggregate 'std::stringstream out' has incomplete type and cannot be defined [C++]
提问by Technupe
I am new to c++ please help me figure out what is wrong with this
我是 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();
采纳答案by nathan
You seem to be missing an include for stringstream. On top of that you have a typo
您似乎缺少 stringstream 的包含。最重要的是你有一个错字
out << end1;
should read
应该读
out << endl;
l
instead of 1
.
l
而不是1
.
回答by Alnitak
Did you:
你是否:
#include <sstream>
Also, the second to last line should be endl
(nb: lower-case L) not end1
(number one).
此外,倒数第二行应该是endl
(nb:小写 L)而不是end1
(第一)。
The code below compiles and works correctly with G++ 4.2.1 on MacOS X
下面的代码在 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;
}
Omitting the #include <sstream>
causes exactly the same error on my system as your first error.
忽略#include <sstream>
导致我系统上的错误与您的第一个错误完全相同的原因。
回答by karlphillip
It's an lowercase L
and not 1
:
这是一个小写L
而不是1
:
out << endl;
I think @Bo is right, (sorry and thanks) change it to std::stringstream out;
我认为@Bo 是对的,(抱歉和感谢)将其更改为 std::stringstream out;