开发者

aggregate 'std::stringstream out' has incomplete type and cannot be defined [C++] [closed]

开发者 https://www.devze.com 2023-02-28 13:26 出处:网络
开发者_JAVA技巧 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not
开发者_JAVA技巧 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I am new to c++ please help me figure out what is wrong with this

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


Did you:

#include <sstream>

Also, the second to last line should be endl (nb: lower-case L) not end1 (number one).

The code below compiles and works correctly with G++ 4.2.1 on MacOS X

#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.


It's an lowercase L and not 1:

out << endl;

I think @Bo is right, (sorry and thanks) change it to std::stringstream out;


You seem to be missing an include for stringstream. On top of that you have a typo

out << end1;

should read

out << endl;

l instead of 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消