我是 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();
你是否:
#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>
原因与您的第一个错误完全相同。
这是一个小写字母L
,而不是1
:
out << endl;
我认为@Bo 是对的,(对不起,谢谢)将其更改为std::stringstream out;
您似乎缺少 stringstream 的包含。最重要的是你有一个错字
out << end1;
应该读
out << endl;
l
而不是1
.